Zelda Classic Coverage Report


Directory: src/
File: src/zc/script_drawing.cpp
Date: 2023-06-04 09:27:51
Exec Total Coverage
Lines: 1312 5112 25.7%
Functions: 47 103 45.6%
Branches: 568 2633 21.6%

Line Branch Exec Source
1 // This program is free software; you can redistribute it and/or modify it under the terms of the
2 // modified version 3 of the GNU General Public License. See License.txt for details.
3
4 //! ritate_sprite_trans doesn't seem to be supported by or allegro header !?
5
6 //glibc 2.28 and later require this: -Z
7 #ifdef __GNUG__
8 #define ALLEGRO_NO_FIX_ALIASES
9 #endif
10
11 #define LOG_BMPBLIT_LEVEL 0
12 #include "base/zc_alleg.h"
13 #include "zc/script_drawing.h"
14 #include "zc/rendertarget.h"
15 #include "zc/maps.h"
16 #include "tiles.h"
17
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 #include "zc/zelda.h"
18 #include "zc/ffscript.h"
19 #include "base/util.h"
20 #include "subscr.h"
21 #include "drawing.h"
22 using namespace util;
23 extern FFScript FFCore;
24 extern ZModule zcm;
25 extern refInfo *ri;
26 extern script_bitmaps scb;
27 #include <stdio.h>
28 #include <fstream>
29
30 #define DegtoFix(d) ((d)*0.7111111111111)
31 #define RadtoFix(d) ((d)*40.743665431525)
32
33 inline double sd_log2( double n )
34 {
35 // log(n)/log(2) is log2.
36 double v = log( (double)n ) / log( (double)2 );
37 return v;
38 }
39
40 inline bool isPowerOfTwo(int32_t n)
41 {
42 if(n==0)
43 return false;
44
45 return (ceil(sd_log2(n)) == floor(sd_log2(n)));
46 }
47
48
49
50 template<class T> inline
51 148904 fixed degrees_to_fixed(T d)
52 {
53 148904 return ftofix(DegtoFix(d));
54 }
55 template<class T> inline
56 fixed radians_to_fixed(T d)
57 {
58 return ftofix(RadtoFix(d));
59 }
60
61 BITMAP* ScriptDrawingBitmapPool::_parent_bmp = 0;
62
63 class TileHelper
64 {
65 public:
66
67 17420 static void OldPutTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
68 {
69 // Past the end of the tile page?
70
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17420 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17420 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
71 {
72 byte w2=(tile+w)%TILES_PER_ROW;
73 OldPutTile(_Dest, tile, x, y, w-w2, h, color, flip);
74 OldPutTile(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip);
75 return;
76 }
77
78
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 17420 times.
17420 switch(flip)
79 {
80 case 1:
81 for(int32_t j=0; j<h; j++)
82 for(int32_t k=w-1; k>=0; k--)
83 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip);
84
85 break;
86
87 case 2:
88 for(int32_t j=h-1; j>=0; j--)
89 for(int32_t k=0; k<w; k++)
90 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip);
91
92 break;
93
94 case 3:
95 for(int32_t j=h-1; j>=0; j--)
96 for(int32_t k=w-1; k>=0; k--)
97 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip);
98
99 break;
100
101 17420 case 0:
102 default:
103
2/2
✓ Branch 0 taken 17420 times.
✓ Branch 1 taken 17420 times.
34840 for(int32_t j=0; j<h; j++)
104
2/2
✓ Branch 0 taken 17420 times.
✓ Branch 1 taken 17420 times.
34840 for(int32_t k=0; k<w; k++)
105 34840 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip);
106
107 17420 break;
108 }
109 17420 }
110
111 2014466 static void OverTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
112 {
113 2014466 overtileblock16(_Dest,tile,x,y,w,h,color,flip,skiprows);
114 2014466 }
115
116 static void OverTileCloaked(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t flip, byte skiprows=0)
117 {
118 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
119 {
120 byte w2=(tile+w)%TILES_PER_ROW;
121 OverTileCloaked(_Dest, tile, x, y, w-w2, h, flip);
122 OverTileCloaked(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, flip);
123 return;
124 }
125
126 switch(flip)
127 {
128 case 1:
129 for(int32_t j=0; j<h; j++)
130 for(int32_t k=w-1; k>=0; k--)
131 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, flip);
132
133 break;
134
135 case 2:
136 for(int32_t j=h-1; j>=0; j--)
137 for(int32_t k=0; k<w; k++)
138 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, flip);
139
140 break;
141
142 case 3:
143 for(int32_t j=h-1; j>=0; j--)
144 for(int32_t k=w-1; k>=0; k--)
145 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, flip);
146
147 break;
148
149 default:
150 for(int32_t j=0; j<h; j++)
151 for(int32_t k=0; k<w; k++)
152 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, flip);
153
154 break;
155 }
156 }
157
158 22375 static void OverTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
159 {
160
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 22375 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
22375 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
161 {
162 byte w2=(tile+w)%TILES_PER_ROW;
163 OverTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
164 OverTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
165 return;
166 }
167
168
1/4
✓ Branch 0 taken 22375 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
22375 switch(flip)
169 {
170 case 1:
171 for(int32_t j=0; j<h; j++)
172 for(int32_t k=w-1; k>=0; k--)
173 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
174
175 break;
176
177 case 2:
178 for(int32_t j=h-1; j>=0; j--)
179 for(int32_t k=0; k<w; k++)
180 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
181
182 break;
183
184 case 3:
185 for(int32_t j=h-1; j>=0; j--)
186 for(int32_t k=w-1; k>=0; k--)
187 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
188
189 break;
190
191 default:
192
2/2
✓ Branch 0 taken 40737 times.
✓ Branch 1 taken 22375 times.
63112 for(int32_t j=0; j<h; j++)
193
2/2
✓ Branch 0 taken 167451 times.
✓ Branch 1 taken 40737 times.
208188 for(int32_t k=0; k<w; k++)
194 208188 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
195
196 22375 break;
197 }
198 22375 }
199
200 static void PutTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
201 {
202 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
203 {
204 byte w2=(tile+w)%TILES_PER_ROW;
205 PutTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
206 PutTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
207 return;
208 }
209
210 switch(flip)
211 {
212 case 1:
213 for(int32_t j=0; j<h; j++)
214 for(int32_t k=w-1; k>=0; k--)
215 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
216
217 break;
218
219 case 2:
220 for(int32_t j=h-1; j>=0; j--)
221 for(int32_t k=0; k<w; k++)
222 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
223
224 break;
225
226 case 3:
227 for(int32_t j=h-1; j>=0; j--)
228 for(int32_t k=w-1; k>=0; k--)
229 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
230
231 break;
232
233 default:
234 for(int32_t j=0; j<h; j++)
235 for(int32_t k=0; k<w; k++)
236 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
237
238 break;
239 }
240 }
241 };
242
243
244
245
246 1785700 void do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
247 {
248 //sdci[1]=layer
249 //sdci[2]=x
250 //sdci[3]=y
251 //sdci[4]=x2
252 //sdci[5]=y2
253 //sdci[6]=color
254 //sdci[7]=scale factor
255 //sdci[8]=rotation anchor x
256 //sdci[9]=rotation anchor y
257 //sdci[10]=rotation angle
258 //sdci[11]=fill
259 //sdci[12]=opacity
260
1/2
✓ Branch 0 taken 1785700 times.
✗ Branch 1 not taken.
1785700 if(sdci[7]==0) //scale
261 {
262 return;
263 }
264
265 1785700 int32_t x1=sdci[2]/10000;
266 1785700 int32_t y1=sdci[3]/10000;
267 1785700 int32_t x2=sdci[4]/10000;
268 1785700 int32_t y2=sdci[5]/10000;
269
270
1/2
✓ Branch 0 taken 1785700 times.
✗ Branch 1 not taken.
1785700 if(x1>x2)
271 {
272 zc_swap(x1,x2);
273 }
274
275
1/2
✓ Branch 0 taken 1785700 times.
✗ Branch 1 not taken.
1785700 if(y1>y2)
276 {
277 zc_swap(y1,y2);
278 }
279
280
2/2
✓ Branch 0 taken 1784957 times.
✓ Branch 1 taken 743 times.
1785700 if(sdci[7] != 10000)
281 {
282 743 int32_t w=x2-x1+1;
283 743 int32_t h=y2-y1+1;
284 743 int32_t w2=(w*sdci[7])/10000;
285 743 int32_t h2=(h*sdci[7])/10000;
286 743 x1=x1-((w2-w)/2);
287 743 x2=x2+((w2-w)/2);
288 743 y1=y1-((h2-h)/2);
289 743 y2=y2+((h2-h)/2);
290 743 }
291
292 1785700 int32_t color=sdci[6]/10000;
293
294
2/2
✓ Branch 0 taken 1750915 times.
✓ Branch 1 taken 34785 times.
1785700 if(sdci[12]/10000<=127) //translucent
295 {
296 34785 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
297 34785 }
298
299
2/2
✓ Branch 0 taken 31579 times.
✓ Branch 1 taken 1754121 times.
1785700 if(sdci[10]==0) //no rotation
300 {
301
2/2
✓ Branch 0 taken 418583 times.
✓ Branch 1 taken 1335538 times.
1754121 if(sdci[11]) //filled
302 {
303 1335538 rectfill(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
304 1335538 }
305 else //outline
306 {
307 418583 rect(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
308 }
309 1754121 }
310 else //rotate
311 {
312 int32_t xy[16];
313 31579 int32_t rx=sdci[8]/10000;
314 31579 int32_t ry=sdci[9]/10000;
315 31579 fixed ra1=itofix(sdci[10]%10000)/10000;
316 31579 fixed ra2=itofix(sdci[10]/10000);
317 31579 fixed ra=ra1+ra2;
318 31579 ra = (ra/360)*256;
319
320 31579 fixed fcosa = fixcos(ra);
321 31579 fixed fsina = fixsin(ra);
322
323 31579 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
324 31579 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
325 31579 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
326 31579 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
327 31579 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
328 31579 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
329 31579 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
330 31579 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
331 31579 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
332 31579 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
333 31579 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
334 31579 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
335 31579 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
336 31579 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
337 31579 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
338 31579 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
339
340
1/2
✓ Branch 0 taken 31579 times.
✗ Branch 1 not taken.
31579 if(sdci[11]) //filled
341 {
342 31579 polygon(bmp, 4, xy, color);
343 31579 }
344 else //outline
345 {
346 line(bmp, xy[0], xy[1], xy[10], xy[11], color);
347 line(bmp, xy[2], xy[3], xy[12], xy[13], color);
348 line(bmp, xy[4], xy[5], xy[14], xy[15], color);
349 line(bmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
350 }
351 }
352
353 1785700 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
354 1785700 }
355
356 void do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
357 {
358 //sdci[1]=layer
359 //sdci[2]=x
360 //sdci[3]=y
361 //sdci[4]=tile
362 //sdci[5]=cset
363 //sdci[6]=width
364 //sdci[7]=height
365 //sdci[8]=overlay
366 //sdci[9]=opacity
367
368 int32_t x=sdci[2]/10000;
369 int32_t y=sdci[3]/10000;
370
371 int32_t tile=sdci[4]/10000;
372 int32_t cs=sdci[5]/10000;
373 int32_t w=sdci[6]/10000;
374 int32_t h=sdci[7]/10000;
375 bool overlay=sdci[8];
376 bool trans=(sdci[9]/10000<=127);
377
378 frame2x2(bmp, &QMisc, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
379 }
380
381
382
383 759760 void do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
384 {
385 //sdci[1]=layer
386 //sdci[2]=x
387 //sdci[3]=y
388 //sdci[4]=radius
389 //sdci[5]=color
390 //sdci[6]=scale factor
391 //sdci[7]=rotation anchor x
392 //sdci[8]=rotation anchor y
393 //sdci[9]=rotation angle
394 //sdci[10]=fill
395 //sdci[11]=opacity
396
1/2
✓ Branch 0 taken 759760 times.
✗ Branch 1 not taken.
759760 if(sdci[6]==0) //scale
397 {
398 return;
399 }
400
401 759760 int32_t x1=sdci[2]/10000;
402 759760 int32_t y1=sdci[3]/10000;
403 759760 qword r=sdci[4];
404
405
1/2
✓ Branch 0 taken 759760 times.
✗ Branch 1 not taken.
759760 if(sdci[6] != 10000)
406 {
407 r*=sdci[6];
408 r/=10000;
409 }
410
411 759760 r/=10000;
412 759760 int32_t color=sdci[5]/10000;
413
414
2/2
✓ Branch 0 taken 741960 times.
✓ Branch 1 taken 17800 times.
759760 if(sdci[11]/10000<=127) //translucent
415 {
416 17800 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
417 17800 }
418
419
5/6
✓ Branch 0 taken 8094 times.
✓ Branch 1 taken 751666 times.
✓ Branch 2 taken 183 times.
✓ Branch 3 taken 7911 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 183 times.
759760 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
420 {
421 int32_t xy[2];
422 7911 int32_t rx=sdci[7]/10000;
423 7911 int32_t ry=sdci[8]/10000;
424 7911 fixed ra1=itofix(sdci[9]%10000)/10000;
425 7911 fixed ra2=itofix(sdci[9]/10000);
426 7911 fixed ra=ra1+ra2;
427 7911 ra = (ra/360)*256;
428
429 7911 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
430 7911 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
431 7911 x1=xy[0];
432 7911 y1=xy[1];
433 7911 }
434
435
2/2
✓ Branch 0 taken 749432 times.
✓ Branch 1 taken 10328 times.
759760 if(sdci[10]) //filled
436 {
437 749432 circlefill(bmp, x1+xoffset, y1+yoffset, r, color);
438 749432 }
439 else //outline
440 {
441 10328 circle(bmp, x1+xoffset, y1+yoffset, r, color);
442 }
443
444 759760 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
445 759760 }
446
447
448 void do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
449 {
450 //sdci[1]=layer
451 //sdci[2]=x
452 //sdci[3]=y
453 //sdci[4]=radius
454 //sdci[5]=start angle
455 //sdci[6]=end angle
456 //sdci[7]=color
457 //sdci[8]=scale factor
458 //sdci[9]=rotation anchor x
459 //sdci[10]=rotation anchor y
460 //sdci[11]=rotation angle
461 //sdci[12]=closed
462 //sdci[13]=fill
463 //sdci[14]=opacity
464
465 if(sdci[8]==0) //scale
466 {
467 return;
468 }
469
470 int32_t cx=sdci[2]/10000;
471 int32_t cy=sdci[3]/10000;
472 qword r=sdci[4];
473
474 if(sdci[8] != 10000)
475 {
476 r*=sdci[8];
477 r/=10000;
478 }
479
480 r/=10000;
481
482 int32_t color=sdci[7]/10000;
483
484 fixed ra1=itofix(sdci[11]%10000)/10000;
485 fixed ra2=itofix(sdci[11]/10000);
486 fixed ra=ra1+ra2;
487 ra = (ra/360)*256;
488
489
490 fixed a1=itofix(sdci[5]%10000)/10000;
491 fixed a2=itofix(sdci[5]/10000);
492 fixed sa=a1+a2;
493 sa = (sa/360)*256;
494
495 a1=itofix(sdci[6]%10000)/10000;
496 a2=itofix(sdci[6]/10000);
497 fixed ea=a1+a2;
498 ea = (ea/360)*256;
499
500 if(sdci[11]!=0) //rotation
501 {
502 int32_t rx=sdci[9]/10000;
503 int32_t ry=sdci[10]/10000;
504
505 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
506 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
507 ea-=ra;
508 sa-=ra;
509 }
510
511 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
512 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
513
514 if(sdci[12]) //closed
515 {
516 if(sdci[13]) //filled
517 {
518 clear_bitmap(prim_bmp);
519 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
520 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
521 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
522 int fillx = zc_max(0,fx)+xoffset;
523 int filly = zc_max(0,fy)+yoffset;
524 zprint2("Screen->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
525 floodfill(prim_bmp, fillx, filly, color);
526
527 if(sdci[14]/10000<=127) //translucent
528 {
529 draw_trans_sprite(bmp, prim_bmp, 0,0);
530 }
531 else
532 {
533 draw_sprite(bmp, prim_bmp, 0,0);
534 }
535 }
536 else
537 {
538 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
539 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
540 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
541 }
542 }
543 else
544 {
545 if(sdci[14]/10000<=127) //translucent
546 {
547 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
548 }
549
550 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
551 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
552 }
553 }
554
555
556 1850 void do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
557 {
558 //sdci[1]=layer
559 //sdci[2]=x
560 //sdci[3]=y
561 //sdci[4]=radiusx
562 //sdci[5]=radiusy
563 //sdci[6]=color
564 //sdci[7]=scale factor
565 //sdci[8]=rotation anchor x
566 //sdci[9]=rotation anchor y
567 //sdci[10]=rotation angle
568 //sdci[11]=fill
569 //sdci[12]=opacity
570
571
1/2
✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
1850 if(sdci[7]==0) //scale
572 {
573 return;
574 }
575
576 1850 int32_t x1=sdci[2]/10000;
577 1850 int32_t y1=sdci[3]/10000;
578 1850 int32_t radx=sdci[4]/10000;
579 1850 radx*=sdci[7]/10000;
580 1850 int32_t rady=sdci[5]/10000;
581 1850 rady*=sdci[7]/10000;
582 1850 int32_t color=sdci[6]/10000;
583 1850 float rotation = sdci[10]/10000;
584
585 1850 int32_t rx=sdci[8]/10000;
586 1850 int32_t ry=sdci[9]/10000;
587 1850 fixed ra1=itofix(sdci[10]%10000)/10000;
588 1850 fixed ra2=itofix(sdci[10]/10000);
589 1850 fixed ra=ra1+ra2;
590 1850 ra = (ra/360)*256;
591
592 int32_t xy[2];
593 1850 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
594 1850 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
595 1850 x1=xy[0];
596 1850 y1=xy[1];
597
598
6/8
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 1687 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 1687 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1687 times.
1850 if(radx<1||rady<1||radx>255||rady>255) return;
599
600 1687 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
601
602
2/2
✓ Branch 0 taken 1630 times.
✓ Branch 1 taken 57 times.
1687 if(sdci[11]) //filled
603 {
604
605
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 606 times.
1630 if(sdci[12]/10000<128) //translucent
606 {
607 1024 clear_bitmap(prim_bmp);
608
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
609 1024 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
610 1024 draw_trans_sprite(bmp, prim_bmp, 0, 0);
611 1024 }
612 else // no opacity
613 {
614
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
615 606 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
616 }
617 1630 }
618 else //not filled
619 {
620
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 43 times.
57 if(sdci[12]/10000<128) //translucent
621 {
622 14 clear_bitmap(prim_bmp);
623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
624 14 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
625 14 draw_trans_sprite(bmp, prim_bmp, 0, 0);
626 14 }
627 else // no opacity
628 {
629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
630 43 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
631 }
632 }
633
634 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
635 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
636 // the ellipse, but it shouldn't be used anyway.
637
1/2
✓ Branch 0 taken 1687 times.
✗ Branch 1 not taken.
1687 if(color==0)
638 {
639 // This is very slow, so check the smallest possible square
640 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
641 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
642
643 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
644 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
645 if(getpixel(bmp, x, y)==255)
646 putpixel(bmp, x, y, 0);
647 }
648
649 1687 script_drawing_commands.ReleaseSubBitmap(bitty);
650 1850 }
651
652
653 933117 void do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
654 {
655 //sdci[1]=layer
656 //sdci[2]=x
657 //sdci[3]=y
658 //sdci[4]=x2
659 //sdci[5]=y2
660 //sdci[6]=color
661 //sdci[7]=scale factor
662 //sdci[8]=rotation anchor x
663 //sdci[9]=rotation anchor y
664 //sdci[10]=rotation angle
665 //sdci[11]=opacity
666
1/2
✓ Branch 0 taken 933117 times.
✗ Branch 1 not taken.
933117 if(sdci[7]==0) //scale
667 {
668 return;
669 }
670
671 933117 int32_t x1=sdci[2]/10000;
672 933117 int32_t y1=sdci[3]/10000;
673 933117 int32_t x2=sdci[4]/10000;
674 933117 int32_t y2=sdci[5]/10000;
675
676
2/2
✓ Branch 0 taken 484795 times.
✓ Branch 1 taken 448322 times.
933117 if(sdci[7] != 10000)
677 {
678 448322 int32_t w=x2-x1+1;
679 448322 int32_t h=y2-y1+1;
680 448322 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
681 448322 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
682 448322 x1=x1-((w2-w)/2);
683 448322 x2=x2+((w2-w)/2);
684 448322 y1=y1-((h2-h)/2);
685 448322 y2=y2+((h2-h)/2);
686 448322 }
687
688 933117 int32_t color=sdci[6]/10000;
689
690
1/2
✓ Branch 0 taken 933117 times.
✗ Branch 1 not taken.
933117 if(sdci[11]/10000<=127) //translucent
691 {
692 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
693 }
694
695
1/2
✓ Branch 0 taken 933117 times.
✗ Branch 1 not taken.
933117 if(sdci[10]!=0) //rotation
696 {
697 int32_t xy[4];
698 int32_t rx=sdci[8]/10000;
699 int32_t ry=sdci[9]/10000;
700 fixed ra1=itofix(sdci[10]%10000)/10000;
701 fixed ra2=itofix(sdci[10]/10000);
702 fixed ra=ra1+ra2;
703
704 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
705 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
706 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
707 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
708 x1=xy[0];
709 y1=xy[1];
710 x2=xy[2];
711 y2=xy[3];
712 }
713
714 933117 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
715 933117 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
716 933117 }
717
718 void do_linesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
719 {
720 //sdci[1]=layer
721 //sdci[2]=array[10] = { x, y, x2, y2, colour, scale, rx, ry, angle, opacity }
722
723 //sdci[2]=x
724 //sdci[3]=y
725 //sdci[4]=x2
726 //sdci[5]=y2
727 //sdci[6]=color
728 //sdci[7]=scale factor
729 //sdci[8]=rotation anchor x
730 //sdci[9]=rotation anchor y
731 //sdci[10]=rotation angle
732 //sdci[11]=opacity
733 //if(sdci[7]==0) //scale
734 //{
735 // return;
736 //}
737
738 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
739
740 if(!v_ptr)
741 {
742 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
743 return;
744 }
745
746 std::vector<int32_t> &v = *v_ptr;
747
748 if(v.empty())
749 return;
750 //Z_scripterrlog("PutPixels reached line %d\n", 983);
751
752 int32_t* pos = &v[0];
753 int32_t sz = v.size();
754
755 for ( int32_t q = 0; q < sz; q+=10 )
756 {
757
758 int32_t x1 = v.at(q);
759 Z_scripterrlog("Lines( x1 ) is: %d\n", x1);
760 int32_t y1 = v.at(q+1);
761 Z_scripterrlog("Lines( x2 ) is: %d\n", y1);
762 int32_t x2 = v.at(q+2);
763 Z_scripterrlog("Lines( x2 ) is: %d\n", x2);
764 int32_t y2 = v.at(q+3);
765 Z_scripterrlog("Lines( y2 ) is: %d\n", y2);
766 int32_t color = v.at(q+4);
767 Z_scripterrlog("Lines( colour ) is: %d\n", color);
768 Z_scripterrlog("Lines( scale ) is: %d\n", v.at(q+5));
769 if (v.at(q+5) == 0) { Z_scripterrlog("Lines() aborting due to scale\n"); return; }//scale
770
771 if( v.at(q+5) != 10000)
772 {
773 int32_t w=x2-x1+1;
774 int32_t h=y2-y1+1;
775 int32_t w2=int32_t(w*((double)v.at(q+5)));
776 int32_t h2=int32_t(h*((double)v.at(q+5)));
777 x1=x1-((w2-w)/2);
778 x2=x2+((w2-w)/2);
779 y1=y1-((h2-h)/2);
780 y2=y2+((h2-h)/2);
781 }
782
783
784 Z_scripterrlog("Lines( opacity ) is: %d\n", v.at(q+9));
785 if(v.at(q+9) <= 127) //translucent
786 {
787 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
788 }
789 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
790 Z_scripterrlog("Lines( rotation ) is: %d\n", v.at(q+8));
791 Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+6));
792 Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+7));
793 if( v.at(q+8) !=0 ) //rotation
794 {
795 int32_t xy[4];
796
797 int32_t rx = v.at(q+6);
798
799 int32_t ry = v.at(q+7);
800
801 fixed ra1=itofix(v.at(q+8) % 1);
802 fixed ra2=itofix(v.at(q+8));
803 fixed ra=ra1+ra2;
804
805 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
806 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
807 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
808 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
809 x1=xy[0];
810 y1=xy[1];
811 x2=xy[2];
812 y2=xy[3];
813 }
814 Z_scripterrlog("Lines( xofs ) is: %d\n", xoffset);
815 Z_scripterrlog("Lines( yofs ) is: %d\n", yoffset);
816 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
817 }
818 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
819 }
820
821 void do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
822 {
823 //sdci[1]=layer
824 //sdci[2]=point count
825 //sdci[3]array[]
826 //sdci[4] = colour
827 //sdci[5] = opacity
828
829 int32_t col = sdci[4]/10000;
830 int32_t op = sdci[5]/10000;
831
832 //bool brokenOffset= ( (get_bit(extra_rules, er_BITMAPOFFSET)!=0) || (get_bit(quest_rules,qr_BITMAPOFFSETFIX)!=0) );
833 //Z_scripterrlog("Broken offset rule for Polygon() is: %s\n", brokenOffset ? "ON" : "OFF");
834 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
835
836 if(!v_ptr)
837 {
838 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
839 return;
840 }
841
842 std::vector<int32_t> &v = *v_ptr;
843
844 if(v.empty())
845 return;
846 //Z_scripterrlog("PutPixels reached line %d\n", 983);
847
848 int32_t* pos = &v[0];
849 int32_t sz = v.size();
850 int32_t numpoints = (sdci[2]/10000);
851 if(sz & 1) --sz; //even amount only
852 if(numpoints > sz/2) //cap to array
853 numpoints = sz/2;
854 if(numpoints < 1)
855 return; //Don't draw 0 or negative point count
856
857 //Fix the draw Y offset. -Z 20th June, 2019
858 for ( int32_t q = 1; q < sz; q+=2 )
859 {
860 pos[q] += yoffset;
861 }
862 if(op <= 127) //translucent
863 {
864 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
865 }
866 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
867
868 polygon(bmp, numpoints, (int32_t*)pos, col);
869 //polygon(bmp, (sdci[2]/10000), &v, col);
870 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
871 }
872
873 void bmp_do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
874 {
875 //sdci[1]=layer
876 //sdci[2]=point count
877 //sdci[3]array[]
878 //sdci[4] = colour
879 //sdci[5] = opacity
880
881 int32_t col = sdci[4]/10000;
882 int32_t op = sdci[5]/10000;
883
884 if ( sdci[17] <= 0 )
885 {
886 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
887 return;
888 }
889 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
890 if ( refbmp == NULL ) return;
891
892 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
893
894 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
895
896 if(!v_ptr)
897 {
898 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
899 return;
900 }
901
902 std::vector<int32_t> &v = *v_ptr;
903
904 if(v.empty())
905 return;
906 //Z_scripterrlog("PutPixels reached line %d\n", 983);
907
908 int32_t* pos = &v[0];
909 int32_t sz = v.size();
910 int32_t numpoints = (sdci[2]/10000);
911 if(sz & 1) --sz; //even amount only
912 if(numpoints > sz/2) //cap to array
913 numpoints = sz/2;
914 if(numpoints < 1)
915 return; //Don't draw 0 or negative point count
916
917 //Fix the draw Y offset. -Z 20th June, 2019
918 for ( int32_t q = 1; q < sz; q+=2 )
919 {
920 pos[q] += yoffset;
921 }
922 if(op <= 127) //translucent
923 {
924 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
925 }
926 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
927
928 polygon(refbmp, numpoints, (int32_t*)pos, col);
929 //polygon(refbmp, (sdci[2]/10000), &v, col);
930 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
931 }
932
933 void do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
934 {
935 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
936
937 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
938 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
939 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
940 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
941 };
942
943 if(sdci[11]/10000 < 128) //translucent
944 {
945 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
946 }
947
948 spline(bmp, points, sdci[10]/10000);
949
950 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
951 }
952
953
954 261359 void do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
955 {
956 //sdci[1]=layer
957 //sdci[2]=x
958 //sdci[3]=y
959 //sdci[4]=color
960 //sdci[5]=rotation anchor x
961 //sdci[6]=rotation anchor y
962 //sdci[7]=rotation angle
963 //sdci[8]=opacity
964 261359 int32_t x1=sdci[2]/10000;
965 261359 int32_t y1=sdci[3]/10000;
966 261359 int32_t color=sdci[4]/10000;
967
968
2/2
✓ Branch 0 taken 261343 times.
✓ Branch 1 taken 16 times.
261359 if(sdci[8]/10000<=127) //translucent
969 {
970 16 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
971 16 }
972
973
1/2
✓ Branch 0 taken 261359 times.
✗ Branch 1 not taken.
261359 if(sdci[7]!=0) //rotation
974 {
975 int32_t xy[2];
976 int32_t rx=sdci[5]/10000;
977 int32_t ry=sdci[6]/10000;
978 fixed ra1=itofix(sdci[7]%10000)/10000;
979 fixed ra2=itofix(sdci[7]/10000);
980 fixed ra=ra1+ra2;
981
982 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
983 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
984 x1=xy[0];
985 y1=xy[1];
986 }
987
988 261359 putpixel(bmp, x1+xoffset, y1+yoffset, color);
989 261359 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
990 261359 }
991
992 void do_putpixelsr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
993 {
994 //Z_scripterrlog("Starting putpixels()%s\n");
995 //sdci[1]=layer
996 //sdci[2]=array {x,y,colour,opacity}
997 //sdci[3]=rotation anchor x
998 //sdci[4]=rotation anchor y
999 //sdci[5]=rotation angle
1000
1001
1002 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1003
1004 if(!v_ptr)
1005 {
1006 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1007 return;
1008 }
1009
1010 std::vector<int32_t> &v = *v_ptr;
1011
1012 if(v.empty())
1013 return;
1014 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1015
1016 int32_t* pos = &v[0];
1017 int32_t sz = v.size();
1018 //Z_scripterrlog("Vector size is: %d\n", sz);
1019 //for ( int32_t m = 0; m < 256; ++m ) Z_scripterrlog("Vector contents at pos[%d]: %d\n", m, pos[m]);
1020
1021 //FFCore.getValues(sdci[2]/10000, points, sz);
1022
1023
1024 int32_t x1 = 0;
1025 int32_t y1 = 0;
1026
1027 for ( int32_t q = 0; q < sz; q+=4 )
1028 {
1029 //Z_scripterrlog("Vector q: %d\n", q);
1030 //if ( q > sz-1 ) break;
1031 x1 = v.at(q); //pos[q];
1032 y1 = v.at(q+1); //pos[q+1];
1033 //Z_scripterrlog("x1 is: %d\n", x1);
1034 //Z_scripterrlog("y1 is: %d\n", 1);
1035 if(sdci[5]!=0) //rotation
1036 {
1037 int32_t xy[2];
1038 int32_t rx=sdci[3]/10000;
1039 int32_t ry=sdci[4]/10000;
1040 fixed ra1=itofix(sdci[5]%10000)/10000;
1041 fixed ra2=itofix(sdci[5]/10000);
1042 fixed ra=ra1+ra2;
1043
1044 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1045 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1046 x1=xy[0];
1047 y1=xy[1];
1048 }
1049 //Z_scripterrlog("PutPixels()%s value is %d\n","x",x1);
1050 //Z_scripterrlog("PutPixels()%s value is %d\n","y",y1);
1051 //Z_scripterrlog("PutPixels()%s value is %d\n","colour",points[q+2]);
1052 if ( v.at(q+3) /*pos[q+3]*/ < 128 ) drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1053 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1054 putpixel(bmp, x1+xoffset, y1+yoffset, v.at(q+2) /*pos[q+2]*/);
1055 //if ( points[q+3] < 128 )
1056
1057 //else drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1058 }
1059 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1060 }
1061
1062 787250 void do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1063 {
1064 //sdci[1]=layer
1065 //sdci[2]=x
1066 //sdci[3]=y
1067 //sdci[4]=tile
1068 //sdci[5]=tile width
1069 //sdci[6]=tile height
1070 //sdci[7]=color (cset)
1071 //sdci[8]=scale x
1072 //sdci[9]=scale y
1073 //sdci[10]=rotation anchor x
1074 //sdci[11]=rotation anchor y
1075 //sdci[12]=rotation angle
1076 //sdci[13]=flip
1077 //sdci[14]=transparency
1078 //sdci[15]=opacity
1079
1080 787250 int32_t w = sdci[5]/10000;
1081 787250 int32_t h = sdci[6]/10000;
1082
1083
4/8
✓ Branch 0 taken 787250 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 787250 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 787250 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 787250 times.
787250 if(w < 1 || h < 1 || h > 20 || w > 20)
1084 {
1085 return;
1086 }
1087
1088 787250 int32_t xscale=sdci[8]/10000;
1089 787250 int32_t yscale=sdci[9]/10000;
1090 787250 int32_t rx = sdci[10]/10000;
1091 787250 int32_t ry = sdci[11]/10000;
1092 787250 float rotation=sdci[12]/10000;
1093 787250 int32_t flip=(sdci[13]/10000)&3;
1094 787250 bool transparency=sdci[14]!=0;
1095 787250 int32_t opacity=sdci[15]/10000;
1096 787250 int32_t color=sdci[7]/10000;
1097
1098 787250 int32_t x1=sdci[2]/10000;
1099 787250 int32_t y1=sdci[3]/10000;
1100
1101 //don't scale if it's not safe to do so
1102 787250 bool canscale = true;
1103
1104
3/4
✓ Branch 0 taken 786211 times.
✓ Branch 1 taken 1039 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 786211 times.
787250 if(xscale==0||yscale==0)
1105 {
1106 1039 return;
1107 }
1108
1109
3/4
✓ Branch 0 taken 68399 times.
✓ Branch 1 taken 717812 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 68399 times.
786211 if(xscale<=0||yscale<=0)
1110 717812 canscale = false; //default size
1111
1112
4/4
✓ Branch 0 taken 68399 times.
✓ Branch 1 taken 717812 times.
✓ Branch 2 taken 42489 times.
✓ Branch 3 taken 675323 times.
786211 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1113 {
1114 110888 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
1115
1116
1/2
✓ Branch 0 taken 110888 times.
✗ Branch 1 not taken.
110888 if(transparency) //transparency
1117 {
1118 110888 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1119 110888 }
1120 else //no transparency
1121 {
1122 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1123 }
1124
1125
2/2
✓ Branch 0 taken 46177 times.
✓ Branch 1 taken 64711 times.
110888 if(rotation != 0)
1126 {
1127 //low negative values indicate no anchor-point rotation
1128
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46177 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46177 if(rx>-777||ry>-777)
1129 {
1130 int32_t xy[2];
1131 46177 fixed ra1=itofix(sdci[12]%10000)/10000;
1132 46177 fixed ra2=itofix(sdci[12]/10000);
1133 46177 fixed ra=ra1+ra2;
1134 46177 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1135 46177 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1136 46177 x1=xy[0];
1137 46177 y1=xy[1];
1138 46177 }
1139
1140
2/2
✓ Branch 0 taken 3688 times.
✓ Branch 1 taken 42489 times.
46177 if(canscale) //scale first
1141 {
1142 //damnit all, .. fixme.
1143
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3688 times.
3688 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1144 3688 clear_bitmap(tempbit);
1145
1146 3688 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1147
1148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
3688 if(opacity < 128)
1149 {
1150 clear_bitmap(prim_bmp);
1151 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1152 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1153 }
1154 else
1155 {
1156 3688 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1157 }
1158
1159 3688 destroy_bitmap(tempbit);
1160 3688 }
1161 else //no scale
1162 {
1163
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 42153 times.
42489 if(opacity < 128)
1164 {
1165 336 clear_bitmap(prim_bmp);
1166 336 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1167 336 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1168 336 }
1169 else
1170 {
1171 42153 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1172 }
1173 }
1174 46177 }
1175 else //scale only
1176 {
1177
1/2
✓ Branch 0 taken 64711 times.
✗ Branch 1 not taken.
64711 if(canscale)
1178 {
1179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64711 times.
64711 if(opacity<128)
1180 {
1181 clear_bitmap(prim_bmp);
1182 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1183 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1184 }
1185 else
1186 {
1187 64711 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1188 }
1189 64711 }
1190 else //error -do not scale
1191 {
1192 if(opacity<128)
1193 {
1194 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1195 }
1196 else
1197 {
1198 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1199 }
1200 }
1201 }
1202
1203 110888 script_drawing_commands.ReleaseSubBitmap(pbitty);
1204
1205 110888 }
1206 else // no scale or rotation
1207 {
1208
1/2
✓ Branch 0 taken 675323 times.
✗ Branch 1 not taken.
675323 if(transparency)
1209 {
1210
2/2
✓ Branch 0 taken 7384 times.
✓ Branch 1 taken 667939 times.
675323 if(opacity<=127)
1211 7384 TileHelper::OverTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1212 else
1213 667939 TileHelper::OverTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1214 675323 }
1215 else
1216 {
1217 if(opacity<=127)
1218 TileHelper::PutTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1219 else
1220 TileHelper::OldPutTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1221 }
1222 }
1223 787250 }
1224
1225 void do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1226 {
1227 //sdci[1]=layer
1228 //sdci[2]=x
1229 //sdci[3]=y
1230 //sdci[4]=tile
1231 //sdci[5]=tile width
1232 //sdci[6]=tile height
1233 //sdci[7]=flip
1234
1235 int32_t w = sdci[5]/10000;
1236 int32_t h = sdci[6]/10000;
1237
1238 if(w < 1 || h < 1 || h > 20 || w > 20)
1239 {
1240 return;
1241 }
1242
1243 int32_t flip=(sdci[7]/10000)&3;
1244
1245 int32_t x1=sdci[2]/10000;
1246 int32_t y1=sdci[3]/10000;
1247
1248 TileHelper::OverTileCloaked(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
1249 }
1250
1251
1252 1198548 void do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1253 {
1254 //sdci[1]=layer
1255 //sdci[2]=x
1256 //sdci[3]=y
1257 //sdci[4]=combo
1258 //sdci[5]=tile width
1259 //sdci[6]=tile height
1260 //sdci[7]=color (cset)
1261 //sdci[8]=scale x
1262 //sdci[9]=scale y
1263 //sdci[10]=rotation anchor x
1264 //sdci[11]=rotation anchor y
1265 //sdci[12]=rotation angle
1266 //sdci[13]=frame
1267 //sdci[14]=flip
1268 //sdci[15]=transparency
1269 //sdci[16]=opacity
1270
1271 1198548 int32_t w = sdci[5]/10000;
1272 1198548 int32_t h = sdci[6]/10000;
1273
1274
4/8
✓ Branch 0 taken 1198548 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1198548 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1198548 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1198548 times.
1198548 if(w<1||h<1||h>20||w>20)
1275 {
1276 return;
1277 }
1278 1198548 int32_t cmb = (sdci[4]/10000);
1279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1198548 times.
1198548 if((unsigned)cmb >= MAXCOMBOS)
1280 {
1281 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1282 return;
1283 }
1284
1285 1198548 int32_t xscale=sdci[8]/10000;
1286 1198548 int32_t yscale=sdci[9]/10000;
1287 1198548 int32_t rx = sdci[10]/10000; //these work now
1288 1198548 int32_t ry = sdci[11]/10000; //these work now
1289 1198548 float rotation=sdci[12]/10000;
1290
1291 1198548 bool transparency=sdci[15]!=0;
1292 1198548 int32_t opacity=sdci[16]/10000;
1293 1198548 int32_t color=sdci[7]/10000;
1294 1198548 int32_t x1=sdci[2]/10000;
1295 1198548 int32_t y1=sdci[3]/10000;
1296
1297 1198548 const newcombo & c = combobuf[cmb];
1298 1198548 int32_t tiletodraw = combo_tile(c, x1, y1);
1299 1198548 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
1300 1198548 int32_t skiprows=c.skipanimy;
1301
1302
1303 //don't scale if it's not safe to do so
1304 1198548 bool canscale = true;
1305
1306
3/4
✓ Branch 0 taken 1198532 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1198532 times.
1198548 if(xscale==0||yscale==0)
1307 {
1308 16 return;
1309 }
1310
1311
3/4
✓ Branch 0 taken 13100 times.
✓ Branch 1 taken 1185432 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13100 times.
1198532 if(xscale<=0||yscale<=0)
1312 1185432 canscale = false; //default size
1313
1314
4/4
✓ Branch 0 taken 13100 times.
✓ Branch 1 taken 1185432 times.
✓ Branch 2 taken 94250 times.
✓ Branch 3 taken 1091182 times.
1198532 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1315 {
1316 107350 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
1317
1318
1/2
✓ Branch 0 taken 107350 times.
✗ Branch 1 not taken.
107350 if(transparency)
1319 {
1320 107350 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1321 107350 }
1322 else //no transparency
1323 {
1324 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1325 }
1326
1327
2/2
✓ Branch 0 taken 94359 times.
✓ Branch 1 taken 12991 times.
107350 if(rotation != 0) // rotate
1328 {
1329 //fixed point sucks ;0
1330
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 94359 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
94359 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
1331 {
1332 int32_t xy[2];
1333 94359 fixed ra1=itofix(sdci[12]%10000)/10000;
1334 94359 fixed ra2=itofix(sdci[12]/10000);
1335 94359 fixed ra=ra1+ra2;
1336 94359 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1337 94359 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1338 94359 x1=xy[0];
1339 94359 y1=xy[1];
1340 94359 }
1341
1342
2/2
✓ Branch 0 taken 109 times.
✓ Branch 1 taken 94250 times.
94359 if(canscale) //scale first
1343 {
1344
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 109 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 109 times.
109 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1345 109 clear_bitmap(tempbit);
1346
1347 109 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1348
1349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 109 times.
109 if(opacity < 128)
1350 {
1351 clear_bitmap(prim_bmp);
1352 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1353 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1354 }
1355 else
1356 {
1357 109 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1358 }
1359
1360 109 destroy_bitmap(tempbit);
1361 109 }
1362 else //no scale
1363 {
1364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94250 times.
94250 if(opacity < 128)
1365 {
1366 clear_bitmap(prim_bmp);
1367 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1368 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1369 }
1370 else
1371 {
1372 94250 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1373 }
1374 }
1375 94359 }
1376 else //scale only
1377 {
1378
1/2
✓ Branch 0 taken 12991 times.
✗ Branch 1 not taken.
12991 if(canscale)
1379 {
1380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12991 times.
12991 if(opacity<128)
1381 {
1382 clear_bitmap(prim_bmp);
1383 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1384 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1385 }
1386 else
1387 {
1388 12991 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1389 }
1390 12991 }
1391 else //error -do not scale
1392 {
1393 if(opacity<128)
1394 {
1395 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1396 }
1397 else
1398 {
1399 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1400 }
1401 }
1402 }
1403
1404 107350 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
1405 107350 }
1406 else // no scale or rotation
1407 {
1408
1/2
✓ Branch 0 taken 1091182 times.
✗ Branch 1 not taken.
1091182 if(transparency)
1409 {
1410
2/2
✓ Branch 0 taken 14991 times.
✓ Branch 1 taken 1076191 times.
1091182 if(opacity<=127)
1411 14991 TileHelper::OverTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1412 else
1413 1076191 TileHelper::OverTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1414 1091182 }
1415 else
1416 {
1417 if(opacity<=127)
1418 TileHelper::PutTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1419 else
1420 TileHelper::OldPutTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1421 }
1422 }
1423 1198548 }
1424
1425 void do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1426 {
1427 //sdci[1]=layer
1428 //sdci[2]=x
1429 //sdci[3]=y
1430 //sdci[4]=combo
1431 //sdci[5]=tile width
1432 //sdci[6]=tile height
1433 //sdci[7]=flip
1434
1435 int32_t w = sdci[5]/10000;
1436 int32_t h = sdci[6]/10000;
1437
1438 if(w<1||h<1||h>20||w>20)
1439 {
1440 return;
1441 }
1442 int32_t cmb = (sdci[4]/10000);
1443 if((unsigned)cmb >= MAXCOMBOS)
1444 {
1445 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1446 return;
1447 }
1448
1449 int32_t x1=sdci[2]/10000;
1450 int32_t y1=sdci[3]/10000;
1451
1452 const newcombo & c = combobuf[cmb];
1453 int32_t tiletodraw = combo_tile(c, x1, y1);
1454 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
1455 int32_t skiprows=c.skipanimy;
1456
1457 TileHelper::OverTileCloaked(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
1458 }
1459
1460
1461 3095380 void do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1462 {
1463 /* layer, x, y, tile, color opacity */
1464
1465 3095380 int32_t opacity = sdci[6]/10000;
1466
1467
2/2
✓ Branch 0 taken 52627 times.
✓ Branch 1 taken 3042753 times.
3095380 if(opacity < 128)
1468 52627 overtiletranslucent16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
1469 else
1470 3042753 overtile16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
1471 3095380 }
1472
1473 void do_fasttilesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1474 {
1475 /* layer, x, y, tile, color opacity */
1476
1477 //sdci[1]=layer
1478 //sdci[2]=array {x,y,tile,colour,opacity}
1479
1480 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1481
1482 if(!v_ptr)
1483 {
1484 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1485 return;
1486 }
1487
1488 std::vector<int32_t> &v = *v_ptr;
1489
1490 if(v.empty())
1491 return;
1492 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1493
1494 int32_t* pos = &v[0];
1495 int32_t sz = v.size();
1496
1497 for ( int32_t q = 0; q < sz; q+=5 )
1498 {
1499
1500 if(v.at(q+4) < 128)
1501 overtiletranslucent16(bmp, v.at(q), xoffset+(v.at(q+1)), yoffset+(v.at(q+2)), v.at(q+3), 0, v.at(q+4));
1502 else
1503 overtile16(bmp, v.at(q), xoffset+(v.at(q+1)), yoffset+(v.at(q+2)), v.at(q+3), 0);
1504 }
1505 }
1506
1507
1508
1509 9915097 void do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1510 {
1511 /* layer, x, y, tile, color opacity */
1512
1513 9915097 int32_t opacity = sdci[6] / 10000;
1514 9915097 int32_t x1 = sdci[2] / 10000;
1515 9915097 int32_t y1 = sdci[3] / 10000;
1516
1517 9915097 int32_t cmb = (sdci[4]/10000);
1518
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9915097 times.
9915097 if((unsigned)cmb >= MAXCOMBOS)
1519 {
1520 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1521 return;
1522 }
1523 //if( index >= MAXCOMBOS ) return; //bleh.
1524 /*
1525 const newcombo & c = combobuf[index];
1526
1527 if(opacity < 128)
1528 overtiletranslucent16(bmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip, opacity);
1529 else
1530 overtile16(bmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip);
1531 */
1532
1533
2/2
✓ Branch 0 taken 5426 times.
✓ Branch 1 taken 9909671 times.
9915097 if(opacity < 128)
1534 {
1535 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
1536 5426 overcomboblocktranslucent(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
1537
1538 5426 }
1539 else
1540 {
1541 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
1542 9909671 overcomboblock(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
1543 }
1544 9915097 }
1545
1546 void do_fastcombosr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1547 {
1548 /* layer, x, y, combo, cset, opacity */
1549
1550 //sdci[1]=layer
1551 //sdci[2]=array {x,y,combo,cset,opacity}
1552
1553 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1554
1555 if(!v_ptr)
1556 {
1557 al_trace("Screen->FastCombos: Vector pointer is null! Internal error. \n");
1558 return;
1559 }
1560
1561 std::vector<int32_t> &v = *v_ptr;
1562
1563 if(v.empty())
1564 return;
1565
1566 int32_t* pos = &v[0];
1567 int32_t sz = v.size();
1568
1569 for ( int32_t q = 0; q < sz; q+=5 )
1570 {
1571 if((unsigned)(v.at(q+2)) >= MAXCOMBOS)
1572 {
1573 Z_scripterrlog("FastCombos() cannot draw combo '%d', as it is out of bounds.\n", v.at(q+2));
1574 continue;
1575 }
1576 if(v.at(q+4) < 128)
1577 {
1578 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
1579 overcomboblocktranslucent(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1, 128);
1580
1581 }
1582 else
1583 {
1584 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
1585 overcomboblock(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1);
1586 }
1587 }
1588 }
1589
1590
1591
1592
1593 936091 void do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1594 {
1595 //broken 2.50.2 and earlier drawcharacter()
1596
2/2
✓ Branch 0 taken 11595 times.
✓ Branch 1 taken 924496 times.
936091 if ( get_bit(quest_rules, qr_BROKENCHARINTDRAWING) )
1597 {
1598 //sdci[1]=layer
1599 //sdci[2]=x
1600 //sdci[3]=y
1601 //sdci[4]=font
1602 //sdci[5]=color
1603 //sdci[6]=bg color
1604 //sdci[7]=strech x (width)
1605 //sdci[8]=stretch y (height)
1606 //sdci[9]=char
1607 //sdci[10]=opacity
1608
1609 11595 int32_t x=sdci[2]/10000;
1610 11595 int32_t y=sdci[3]/10000;
1611 11595 int32_t font_index=sdci[4]/10000;
1612 11595 int32_t color=sdci[5]/10000;
1613 11595 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1614 11595 int32_t w=sdci[7]/10000;
1615 11595 int32_t h=sdci[8]/10000;
1616 11595 char glyph=char(sdci[9]/10000);
1617 11595 int32_t opacity=sdci[10]/10000;
1618
1619 //safe check
1620
1/2
✓ Branch 0 taken 11595 times.
✗ Branch 1 not taken.
11595 if(bg_color < -1) bg_color = -1;
1621
1622
1/2
✓ Branch 0 taken 11595 times.
✗ Branch 1 not taken.
11595 if(w>512) w=512; //w=vbound(w,0,512);
1623
1624
1/2
✓ Branch 0 taken 11595 times.
✗ Branch 1 not taken.
11595 if(h>512) h=512; //h=vbound(h,0,512);
1625
1626 //undone
1627
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11595 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11595 if(w>0&&h>0)//stretch the character
1628 {
1629 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1630
1631 if(opacity < 128)
1632 {
1633 if(w>128||h>128)
1634 {
1635 clear_bitmap(prim_bmp);
1636
1637 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1638 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1639 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1640 }
1641 else //this is faster
1642 {
1643 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1644
1645 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1646 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1647 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1648
1649 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1650 }
1651 }
1652 else // no opacity
1653 {
1654 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1655 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1656 }
1657
1658 }
1659 else //no stretch
1660 {
1661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11595 times.
11595 if(opacity < 128)
1662 {
1663 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1664 clear_bitmap(pbmp);
1665
1666 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1667 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1668
1669 destroy_bitmap(pbmp);
1670 }
1671 else // no opacity
1672 {
1673 11595 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1674 }
1675 }
1676 11595 }
1677
1678 else //2.53.0 fixed version and later.
1679 {
1680
1681 //sdci[1]=layer
1682 //sdci[2]=x
1683 //sdci[3]=y
1684 //sdci[4]=font
1685 //sdci[5]=color
1686 //sdci[6]=bg color
1687 //sdci[7]=strech x (width)
1688 //sdci[8]=stretch y (height)
1689 //sdci[9]=char
1690 //sdci[10]=opacity
1691
1692 924496 int32_t x=sdci[2]/10000;
1693 924496 int32_t y=sdci[3]/10000;
1694 924496 int32_t font_index=sdci[4]/10000;
1695 924496 int32_t color=sdci[5]/10000;
1696 924496 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1697 924496 int32_t w=sdci[7]/10000;
1698 924496 int32_t h=sdci[8]/10000;
1699 924496 char glyph=char(sdci[9]/10000);
1700 924496 int32_t opacity=sdci[10]/10000;
1701
1702 //safe check
1703
1/2
✓ Branch 0 taken 924496 times.
✗ Branch 1 not taken.
924496 if(bg_color < -1) bg_color = -1;
1704
1705
1/2
✓ Branch 0 taken 924496 times.
✗ Branch 1 not taken.
924496 if(w>512) w=512; //w=vbound(w,0,512);
1706
1707
1/2
✓ Branch 0 taken 924496 times.
✗ Branch 1 not taken.
924496 if(h>512) h=512; //h=vbound(h,0,512);
1708
1709 //undone
1710
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 924496 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
924496 if(w>0&&h>0)//stretch the character
1711 {
1712 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1713
1714 if(opacity < 128)
1715 {
1716 if(w>128||h>128)
1717 {
1718 clear_bitmap(prim_bmp);
1719
1720 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1721 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1722 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1723 }
1724 else //this is faster
1725 {
1726 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1727
1728 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1729 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1730 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1731
1732 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1733 }
1734 }
1735 else // no opacity
1736 {
1737 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1738 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1739 }
1740
1741 }
1742 else //no stretch
1743 {
1744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 924496 times.
924496 if(opacity < 128)
1745 {
1746 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1747 clear_bitmap(pbmp);
1748
1749 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1750 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1751
1752 destroy_bitmap(pbmp);
1753 }
1754 else // no opacity
1755 {
1756 924496 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1757 }
1758 }
1759
1760 }
1761
1762 936091 }
1763
1764
1765 47706 void do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1766 {
1767 //broken 2.50.2 and earlier drawinteger()
1768
2/2
✓ Branch 0 taken 35718 times.
✓ Branch 1 taken 11988 times.
47706 if ( get_bit(quest_rules, qr_BROKENCHARINTDRAWING) )
1769 {
1770 //sdci[1]=layer
1771 //sdci[2]=x
1772 //sdci[3]=y
1773 //sdci[4]=font
1774 //sdci[5]=color
1775 //sdci[6]=bg color
1776 //sdci[7]=strech x (width)
1777 //sdci[8]=stretch y (height)
1778 //sdci[9]=integer
1779 //sdci[10]=num decimal places
1780 //sdci[11]=opacity
1781
1782 35718 int32_t x=sdci[2]/10000;
1783 35718 int32_t y=sdci[3]/10000;
1784 35718 int32_t font_index=sdci[4]/10000;
1785 35718 int32_t color=sdci[5]/10000;
1786 35718 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1787 35718 int32_t w=sdci[7]/10000;
1788 35718 int32_t h=sdci[8]/10000;
1789 //float number=static_cast<float>(sdci[9])/10000.0f;
1790 35718 int32_t decplace=sdci[10]/10000;
1791 35718 int32_t opacity=sdci[11]/10000;
1792
1793 //safe check
1794
1/2
✓ Branch 0 taken 35718 times.
✗ Branch 1 not taken.
35718 if(bg_color < -1) bg_color = -1;
1795
1796
1/2
✓ Branch 0 taken 35718 times.
✗ Branch 1 not taken.
35718 if(w>512) w=512; //w=vbound(w,0,512);
1797
1798
1/2
✓ Branch 0 taken 35718 times.
✗ Branch 1 not taken.
35718 if(h>512) h=512; //h=vbound(h,0,512);
1799
1800 char numbuf[15];
1801
1802
1/6
✓ Branch 0 taken 35718 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35718 switch(decplace)
1803 {
1804 default:
1805 case 0:
1806 35718 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1807 35718 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1808
1809 case 1:
1810 //sprintf(numbuf,"%.01f",number);
1811 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1812 break;
1813
1814 case 2:
1815 //sprintf(numbuf,"%.02f",number);
1816 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1817 break;
1818
1819 case 3:
1820 //sprintf(numbuf,"%.03f",number);
1821 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1822 break;
1823
1824 case 4:
1825 //sprintf(numbuf,"%.04f",number);
1826 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1827 break;
1828 }
1829
1830
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 35718 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
35718 if(w>0&&h>0)//stretch
1831 {
1832 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1833
1834 if(opacity < 128)
1835 {
1836 if(w>128||h>128)
1837 {
1838 clear_bitmap(prim_bmp);
1839
1840 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1841 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1842 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1843 }
1844 else
1845 {
1846 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1847 clear_bitmap(pbmp2);
1848
1849 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1850 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1851 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1852
1853 destroy_bitmap(pbmp2);
1854 }
1855 }
1856 else // no opacity
1857 {
1858 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1859 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1860 }
1861
1862 }
1863 else //no stretch
1864 {
1865
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35718 times.
35718 if(opacity < 128)
1866 {
1867 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1868 clear_bitmap(pbmp);
1869
1870 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1871 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1872
1873 destroy_bitmap(pbmp);
1874 }
1875 else // no opacity
1876 {
1877 35718 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1878 }
1879 }
1880
1881 35718 }
1882
1883 else //2.53.0 fixed version and later.
1884 {
1885 //sdci[1]=layer
1886 //sdci[2]=x
1887 //sdci[3]=y
1888 //sdci[4]=font
1889 //sdci[5]=color
1890 //sdci[6]=bg color
1891 //sdci[7]=strech x (width)
1892 //sdci[8]=stretch y (height)
1893 //sdci[9]=integer
1894 //sdci[10]=num decimal places
1895 //sdci[11]=opacity
1896
1897 11988 int32_t x=sdci[2]/10000;
1898 11988 int32_t y=sdci[3]/10000;
1899 11988 int32_t font_index=sdci[4]/10000;
1900 11988 int32_t color=sdci[5]/10000;
1901 11988 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1902 11988 int32_t w=sdci[7]/10000;
1903 11988 int32_t h=sdci[8]/10000;
1904 //float number=static_cast<float>(sdci[9])/10000.0f;
1905 //int32_t numberint = sdci[9]/10000;
1906 11988 int32_t decplace=sdci[10]/10000;
1907 11988 int32_t opacity=sdci[11]/10000;
1908
1909 //safe check
1910
1/2
✓ Branch 0 taken 11988 times.
✗ Branch 1 not taken.
11988 if(bg_color < -1) bg_color = -1;
1911
1912
1/2
✓ Branch 0 taken 11988 times.
✗ Branch 1 not taken.
11988 if(w>512) w=512; //w=vbound(w,0,512);
1913
1914
1/2
✓ Branch 0 taken 11988 times.
✗ Branch 1 not taken.
11988 if(h>512) h=512; //h=vbound(h,0,512);
1915
1916 char numbuf[15];
1917
1918
1/6
✓ Branch 0 taken 11988 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11988 switch(decplace)
1919 {
1920 default:
1921 case 0:
1922 11988 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1923 11988 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1924
1925 case 1:
1926 //sprintf(numbuf,"%.01f",number);
1927 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1928 break;
1929
1930 case 2:
1931 //sprintf(numbuf,"%.02f",number);
1932 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1933 break;
1934
1935 case 3:
1936 //sprintf(numbuf,"%.03f",number);
1937 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1938 break;
1939
1940 case 4:
1941 //sprintf(numbuf,"%.04f",number);
1942 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1943 break;
1944 }
1945
1946 //FONT* font=get_zc_font(sdci[4]/10000);
1947
1948
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11988 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11988 if(w>0&&h>0)//stretch
1949 {
1950 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
1951 clear_bitmap(pbmp);
1952 //script_drawing_commands.GetSmallTextureBitmap(1,1);
1953
1954 if(opacity < 128)
1955 {
1956 if(w>128||h>128)
1957 {
1958 clear_bitmap(prim_bmp);
1959
1960 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1961 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1962 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1963 }
1964 else
1965 {
1966 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1967 clear_bitmap(pbmp2);
1968
1969 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1970 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1971 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1972
1973 destroy_bitmap(pbmp2);
1974 }
1975 }
1976 else // no opacity
1977 {
1978 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1979 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1980 }
1981
1982 }
1983 else //no stretch
1984 {
1985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11988 times.
11988 if(opacity < 128)
1986 {
1987 FONT* font = get_zc_font(font_index);
1988 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
1989 clear_bitmap(pbmp);
1990
1991 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
1992 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1993
1994 destroy_bitmap(pbmp);
1995 }
1996 else // no opacity
1997 {
1998 11988 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1999 }
2000 }
2001 }
2002 47706 }
2003
2004
2005 1187639 void do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2006 {
2007 //sdci[1]=layer
2008 //sdci[2]=x
2009 //sdci[3]=y
2010 //sdci[4]=font
2011 //sdci[5]=color
2012 //sdci[6]=bg color
2013 //sdci[7]=format_option
2014 //sdci[8]=string
2015 //sdci[9]=opacity
2016
2017 1187639 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2018
2019
1/2
✓ Branch 0 taken 1187639 times.
✗ Branch 1 not taken.
1187639 if(!str)
2020 {
2021 al_trace("String pointer is null! Internal error. \n");
2022 return;
2023 }
2024
2025 1187639 int32_t x=sdci[2]/10000;
2026 1187639 int32_t y=sdci[3]/10000;
2027 1187639 FONT* font=get_zc_font(sdci[4]/10000);
2028 1187639 int32_t color=sdci[5]/10000;
2029 1187639 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2030 1187639 int32_t format_type=sdci[7]/10000;
2031 1187639 int32_t opacity=sdci[9]/10000;
2032 //sdci[8] not needed :)
2033
2034 //safe check
2035
1/2
✓ Branch 0 taken 1187639 times.
✗ Branch 1 not taken.
1187639 if(bg_color < -1) bg_color = -1;
2036
2037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1187639 times.
1187639 if(opacity < 128)
2038 {
2039 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2040 if (width < 1) return; //SANITY -Em
2041 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2042 clear_bitmap(pbmp);
2043 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2044 if(format_type == 2) // right-sided text
2045 x-=width;
2046 else if(format_type == 1) // centered text
2047 x-=width/2;
2048 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2049 destroy_bitmap(pbmp);
2050 }
2051 else // no opacity
2052 {
2053
2/2
✓ Branch 0 taken 39984 times.
✓ Branch 1 taken 1147655 times.
1187639 if(format_type == 2) // right-sided text
2054 {
2055 39984 textout_right_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2056 39984 }
2057
2/2
✓ Branch 0 taken 524326 times.
✓ Branch 1 taken 623329 times.
1147655 else if(format_type == 1) // centered text
2058 {
2059 524326 textout_centre_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2060 524326 }
2061 else // standard left-sided text
2062 {
2063 623329 textout_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2064 }
2065 }
2066 1187639 }
2067
2068 153213 void do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2069 {
2070 //sdci[1]=layer
2071 //sdci[2]=x
2072 //sdci[3]=y
2073 //sdci[4]=font
2074 //sdci[5]=color
2075 //sdci[6]=bg color
2076 //sdci[7]=format_option
2077 //sdci[8]=string
2078 //sdci[9]=opacity
2079 //sdci[10]=shadowtype
2080 //sdci[11]=shadow_color
2081
2082 153213 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2083
2084
1/2
✓ Branch 0 taken 153213 times.
✗ Branch 1 not taken.
153213 if(!str)
2085 {
2086 al_trace("String pointer is null! Internal error. \n");
2087 return;
2088 }
2089
2090 153213 int32_t x=sdci[2]/10000;
2091 153213 int32_t y=sdci[3]/10000;
2092 153213 FONT* font=get_zc_font(sdci[4]/10000);
2093 153213 int32_t color=sdci[5]/10000;
2094 153213 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2095 153213 int32_t format_type=sdci[7]/10000;
2096 153213 int32_t opacity=sdci[9]/10000;
2097 153213 int32_t textstyle = sdci[10]/10000;
2098 153213 int32_t shadow_color = sdci[11]/10000;
2099 //sdci[8] not needed :)
2100
2101 //safe check
2102
1/2
✓ Branch 0 taken 153213 times.
✗ Branch 1 not taken.
153213 if(bg_color < -1) bg_color = -1;
2103
2104
2/2
✓ Branch 0 taken 740 times.
✓ Branch 1 taken 152473 times.
153213 if(opacity < 128)
2105 {
2106
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2107
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 if (width < 1) return; //SANITY -Em
2108 740 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2109 740 clear_bitmap(pbmp);
2110 740 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
2111 740 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
740 if(format_type == 2) // right-sided text
2113 x-=width;
2114
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 else if(format_type == 1) // centered text
2115 740 x-=width/2;
2116 740 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2117 740 destroy_bitmap(pbmp);
2118 740 }
2119 else // no opacity
2120 {
2121 152473 textout_styled_aligned_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
2122 }
2123 153213 }
2124
2125
2126 9266 void do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2127 {
2128 //sdci[1]=layer
2129 //sdci[2]=x1
2130 //sdci[3]=y1
2131 //sdci[4]=x2
2132 //sdci[5]=y2
2133 //sdci[6]=x3
2134 //sdci[7]=y3
2135 //sdci[8]=x4
2136 //sdci[9]=y4
2137 //sdci[10]=width
2138 //sdci[11]=height
2139 //sdci[12]=cset
2140 //sdci[13]=flip
2141 //sdci[14]=tile/combo
2142 //sdci[15]=polytype
2143
2144 9266 int32_t x1 = sdci[2]/10000;
2145 9266 int32_t y1 = sdci[3]/10000;
2146 9266 int32_t x2 = sdci[4]/10000;
2147 9266 int32_t y2 = sdci[5]/10000;
2148 9266 int32_t x3 = sdci[6]/10000;
2149 9266 int32_t y3 = sdci[7]/10000;
2150 9266 int32_t x4 = sdci[8]/10000;
2151 9266 int32_t y4 = sdci[9]/10000;
2152 9266 int32_t w = sdci[10]/10000;
2153 9266 int32_t h = sdci[11]/10000;
2154 9266 int32_t color = sdci[12]/10000;
2155 9266 int32_t flip=(sdci[13]/10000)&3;
2156 9266 int32_t tile = sdci[14]/10000;
2157 9266 int32_t polytype = sdci[15]/10000;
2158
2159 //todo: finish palette shading
2160 /*
2161 POLYTYPE_FLAT
2162 POLYTYPE_GCOL
2163 POLYTYPE_GRGB
2164 POLYTYPE_ATEX
2165 POLYTYPE_PTEX
2166 POLYTYPE_ATEX_MASK
2167 POLYTYPE_PTEX_MASK
2168 POLYTYPE_ATEX_LIT
2169 POLYTYPE_PTEX_LIT
2170 POLYTYPE_ATEX_MASK_LIT
2171 POLYTYPE_PTEX_MASK_LIT
2172 POLYTYPE_ATEX_TRANS
2173 POLYTYPE_PTEX_TRANS
2174 POLYTYPE_ATEX_MASK_TRANS
2175 POLYTYPE_PTEX_MASK_TRANS
2176 */
2177 9266 polytype = vbound(polytype, 0, 14);
2178
2179
2/4
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9266 times.
9266 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2180 {
2181 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2182 return; //non power of two error
2183 }
2184
2185 9266 int32_t tex_width = w*16;
2186 9266 int32_t tex_height = h*16;
2187
2188 BITMAP *tex;
2189
2190 9266 bool mustDestroyBmp = false;
2191
2192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile > 65519 ) tex = zscriptDrawingRenderTarget->GetBitmapPtr(tile - 65519);
2193 9266 else tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2194
2195
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(!tex)
2196 {
2197 mustDestroyBmp = true;
2198 tex = create_bitmap_ex(8, tex_width, tex_height);
2199 clear_bitmap(tex);
2200 }
2201
2202 int32_t col[4];
2203 /*
2204 if( color < 0 )
2205 {
2206 col[0]=draw_container.color_buffer[0];
2207 col[1]=draw_container.color_buffer[1];
2208 col[2]=draw_container.color_buffer[2];
2209 col[3]=draw_container.color_buffer[3];
2210 }
2211 else */
2212 {
2213 9266 col[0]=col[1]=col[2]=col[3]=color;
2214 }
2215
2216
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9266 if(tile > 0 && tile <= 65519) // TILE
2217 {
2218 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2219 }
2220
2221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile < 0 ) // COMBO
2222 {
2223 9266 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2224 9266 const int32_t tiletodraw = combo_tile(c, x1, y1);
2225 9266 flip = flip ^ c.flip;
2226
2227 9266 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2228 9266 }
2229
2230 9266 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2231 9266 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2232 9266 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2233 9266 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(tex_width), 0, col[3] };
2234
2235 9266 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
2236
2237
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(mustDestroyBmp)
2238 destroy_bitmap(tex);
2239
2240 9266 }
2241
2242
2243 void do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2244 {
2245 //sdci[1]=layer
2246 //sdci[2]=x1
2247 //sdci[3]=y1
2248 //sdci[4]=x2
2249 //sdci[5]=y2
2250 //sdci[6]=x3
2251 //sdci[7]=y3
2252 //sdci[8]=width
2253 //sdci[9]=height
2254 //sdci[10]=cset
2255 //sdci[11]=flip
2256 //sdci[12]=tile/combo
2257 //sdci[13]=polytype
2258
2259 int32_t x1 = sdci[2]/10000;
2260 int32_t y1 = sdci[3]/10000;
2261 int32_t x2 = sdci[4]/10000;
2262 int32_t y2 = sdci[5]/10000;
2263 int32_t x3 = sdci[6]/10000;
2264 int32_t y3 = sdci[7]/10000;
2265 int32_t w = sdci[8]/10000;
2266 int32_t h = sdci[9]/10000;
2267 int32_t color = sdci[10]/10000;
2268 int32_t flip=(sdci[11]/10000)&3;
2269 int32_t tile = sdci[12]/10000;
2270 int32_t polytype = sdci[13]/10000;
2271
2272 polytype = vbound(polytype, 0, 14);
2273
2274 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2275 {
2276 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2277 return; //non power of two error
2278 }
2279
2280 int32_t tex_width = w*16;
2281 int32_t tex_height = h*16;
2282
2283 bool mustDestroyBmp = false;
2284 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2285
2286 if(!tex)
2287 {
2288 mustDestroyBmp = true;
2289 tex = create_bitmap_ex(8, tex_width, tex_height);
2290 clear_bitmap(tex);
2291 }
2292
2293 int32_t col[3];
2294 /*
2295 if( color < 0 )
2296 {
2297 col[0]=draw_container.color_buffer[0];
2298 col[1]=draw_container.color_buffer[1];
2299 col[2]=draw_container.color_buffer[2];
2300 }
2301 else */
2302 {
2303 col[0]=col[1]=col[2]=color;
2304 }
2305
2306 if(tile > 0) // TILE
2307 {
2308 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2309 }
2310 else // COMBO
2311 {
2312 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2313 const int32_t tiletodraw = combo_tile(c, x1, y1);
2314 flip = flip ^ c.flip;
2315
2316 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2317 }
2318
2319 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2320 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2321 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2322
2323
2324 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
2325
2326 if(mustDestroyBmp)
2327 destroy_bitmap(tex);
2328 }
2329
2330
2331 814852 void do_drawbitmapr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2332 {
2333 //sdci[1]=layer
2334 //sdci[2]=bitmap
2335 //sdci[3]=sourcex
2336 //sdci[4]=sourcey
2337 //sdci[5]=sourcew
2338 //sdci[6]=sourceh
2339 //sdci[7]=destx
2340 //sdci[8]=desty
2341 //sdci[9]=destw
2342 //sdci[10]=desth
2343 //sdci[11]=rotation
2344 //sdci[12]=mask
2345
2346 814852 int32_t bitmapIndex = sdci[2]/10000;
2347 814852 int32_t sx = sdci[3]/10000;
2348 814852 int32_t sy = sdci[4]/10000;
2349 814852 int32_t sw = sdci[5]/10000;
2350 814852 int32_t sh = sdci[6]/10000;
2351 814852 int32_t dx = sdci[7]/10000;
2352 814852 int32_t dy = sdci[8]/10000;
2353 814852 int32_t dw = sdci[9]/10000;
2354 814852 int32_t dh = sdci[10]/10000;
2355 814852 float rot = sdci[11]/10000;
2356 814852 bool masked = (sdci[12] != 0);
2357
2358 //bugfix
2359 814852 sx = vbound(sx, 0, 512);
2360 814852 sy = vbound(sy, 0, 512);
2361 814852 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2362 814852 sh = vbound(sh, 0, 512 - sy);
2363
2364
2365
2/4
✓ Branch 0 taken 814852 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 814852 times.
814852 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2366 return;
2367
2368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 814852 times.
814852 bool stretched = (sw != dw || sh != dh);
2369
2370 814852 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2371
2372
1/2
✓ Branch 0 taken 814852 times.
✗ Branch 1 not taken.
814852 if(!sourceBitmap)
2373 {
2374 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2375 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2376 return;
2377 }
2378
2379 814852 BITMAP* subBmp = 0;
2380
2381
1/2
✓ Branch 0 taken 814852 times.
✗ Branch 1 not taken.
814852 if(rot != 0)
2382 {
2383 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2384
2385 if(!subBmp)
2386 {
2387 Z_scripterrlog("DrawBitmap() failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2388 return;
2389 }
2390 }
2391
2392
2393 814852 dx = dx + xoffset;
2394 814852 dy = dy + yoffset;
2395
2396
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 814612 times.
814852 if(stretched)
2397 {
2398
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(masked)
2399 {
2400
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(rot != 0)
2401 {
2402 //if ( rot == 4096 ) { //translucent
2403 // masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2404 // //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2405 // draw_trans_sprite(bmp, subBmp, dx, dy);
2406 // //draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, 0);
2407
2408
2409 // }
2410 //else {
2411 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2412 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2413 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2414 //
2415
2416 // }
2417 }
2418 else
2419 240 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2420 240 }
2421 else
2422 {
2423 if(rot != 0)
2424 {
2425 //if ( rot == 4096 ) { //translucent
2426 // stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2427 // draw_trans_sprite(bmp, subBmp, dx, dy);
2428 // }
2429 //else {
2430 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2431 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2432 // }
2433 }
2434 else
2435 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2436 }
2437 240 }
2438 else
2439 {
2440
1/2
✓ Branch 0 taken 814612 times.
✗ Branch 1 not taken.
814612 if(masked)
2441 {
2442
1/2
✓ Branch 0 taken 814612 times.
✗ Branch 1 not taken.
814612 if(rot != 0)
2443 {
2444 //if ( rot == 4096 ) {//translucent
2445 // masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2446 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2447
2448 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2449 //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2450 // draw_trans_sprite(bmp, subBmp, dx, dy);
2451 // }
2452 //else {
2453 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2454 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2455 // }
2456 }
2457 else
2458 814612 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2459 814612 }
2460 else
2461 {
2462 if(rot != 0)
2463 {
2464 //if ( rot == 4096 ) { //translucent
2465 // blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2466 // draw_trans_sprite(bmp, subBmp, dx, dy);
2467 // }
2468 //else {
2469 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2470 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2471 // }
2472 }
2473 else
2474 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2475 }
2476 }
2477
2478 //cleanup
2479
1/2
✓ Branch 0 taken 814852 times.
✗ Branch 1 not taken.
814852 if(subBmp)
2480 {
2481 script_drawing_commands.ReleaseSubBitmap(subBmp);
2482 }
2483 814852 }
2484
2485
2486 //Draw]()
2487 void do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2488 {
2489 /*
2490 //sdci[1]=layer
2491 //sdci[2]=bitmap
2492 //sdci[3]=sourcex
2493 //sdci[4]=sourcey
2494 //sdci[5]=sourcew
2495 //sdci[6]=sourceh
2496 //sdci[7]=destx
2497 //sdci[8]=desty
2498 //sdci[9]=destw
2499 //sdci[10]=desth
2500 //sdci[11]=rotation/angle
2501 //scdi[12] = pivot cx
2502 //sdci[13] = pivot cy
2503 //scdi[14] = effect flags
2504
2505
2506 const int32_t BITDX_NORMAL = 0;
2507 const int32_t BITDX_TRANS = 1; //Translucent
2508 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
2509 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
2510 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
2511 //Note: Some modes cannot be combined. if a combination is not supported, an error
2512 // detailing this will be shown in allegro.log.
2513
2514 //scdi[15] = litcolour
2515 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2516 /not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2517
2518 //sdci[16]=mask
2519
2520 */
2521
2522 int32_t bitmapIndex = sdci[2]/10000;
2523 int32_t sx = sdci[3]/10000;
2524 int32_t sy = sdci[4]/10000;
2525 int32_t sw = sdci[5]/10000;
2526 int32_t sh = sdci[6]/10000;
2527 int32_t dx = sdci[7]/10000;
2528 int32_t dy = sdci[8]/10000;
2529 int32_t dw = sdci[9]/10000;
2530 int32_t dh = sdci[10]/10000;
2531 float rot = sdci[11]/10000;
2532 int32_t cx = sdci[12]/10000;
2533 int32_t cy = sdci[13]/10000;
2534 int32_t mode = sdci[14]/10000;
2535 int32_t litcolour = sdci[15]/10000;
2536 bool masked = (sdci[16] != 0);
2537
2538
2539
2540 //bugfix
2541 sx = vbound(sx, 0, 512);
2542 sy = vbound(sy, 0, 512);
2543 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2544 sh = vbound(sh, 0, 512 - sy);
2545
2546
2547 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2548 return;
2549
2550 bool stretched = (sw != dw || sh != dh);
2551
2552 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2553
2554 if(!sourceBitmap)
2555 {
2556 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2557 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2558 return;
2559 }
2560
2561 BITMAP* subBmp = 0;
2562
2563 /*
2564 if ( bitmapIndex == -1 ) {
2565 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
2566 }
2567 */
2568
2569 if(rot != 0 || mode != 0)
2570 {
2571 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2572
2573 if(!subBmp)
2574 {
2575 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2576 return;
2577 }
2578 }
2579
2580
2581 dx = dx + xoffset;
2582 dy = dy + yoffset;
2583
2584 if(stretched)
2585 {
2586 if(masked) //stretched and masked
2587 {
2588 if ( rot == 0 ) //if not rotated
2589 {
2590 switch(mode)
2591 {
2592 case 1:
2593 //transparent
2594 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2595 draw_trans_sprite(bmp, subBmp, dx, dy);
2596 break;
2597
2598
2599 case 2:
2600 //pivot?
2601 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2602 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2603 //Pivoting requires two more args
2604 break;
2605
2606 case 3:
2607 //pivot + trans
2608 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2609 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2610 break;
2611
2612 case 4:
2613 //flip v
2614 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2615 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2616 break;
2617
2618 case 5:
2619 //trans + v flip
2620 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2621 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2622 break;
2623
2624 case 6:
2625 //pivot + v flip
2626 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2627 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2628 break;
2629
2630 case 8:
2631 //vlip h
2632 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2633 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2634 break;
2635
2636 case 9:
2637 //trans + h flip
2638 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2639 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2640 break;
2641
2642 case 10:
2643 //flip H and pivot
2644 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2645 //return error cannot pivot and h flip
2646 break;
2647
2648 case 12:
2649 //vh flip
2650 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2651 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2652 break;
2653
2654 case 13:
2655 //trans + vh flip
2656 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2657 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2658 break;
2659
2660 case 14:
2661 //pivot and vh flip
2662 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2663 //return error cannot both pivot and vh flip
2664 break;
2665
2666 case 16:
2667 //lit
2668 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2669 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2670 break;
2671
2672 case 18:
2673 //pivot, lit
2674 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2675 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2676 break;
2677
2678 case 20:
2679 //lit + v flip
2680 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2681 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2682 break;
2683
2684 case 22:
2685 //Pivot, vflip, lit
2686 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2687 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2688 break;
2689
2690 case 24:
2691 //lit + h flip
2692 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2693 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2694 break;
2695
2696 case 26:
2697 //pivot + lit + hflip
2698 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2699 //return error cannot pivot, lit, and flip
2700 break;
2701
2702 case 28:
2703 //lit + vh flip
2704 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2705 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2706 break;
2707
2708 case 32: //gouraud
2709 //Probably not wort supporting.
2710 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2711 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2712 break;
2713
2714 case 0:
2715 //no effect
2716 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2717 break;
2718
2719
2720 default:
2721 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2722
2723
2724 }
2725 } //end if not rotated
2726
2727 if ( rot != 0 ) //if rotated
2728 {
2729 switch(mode)
2730 {
2731 case 1:
2732 //transparent
2733 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2734 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2735
2736 break;
2737
2738 case 2:
2739 //pivot?
2740 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2741 //return an error, cannot both rotate and pivot
2742 break;
2743
2744 case 3:
2745 //pivot + trans
2746 //return an error, cannot both rotate and pivot
2747 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2748 break;
2749
2750 case 4:
2751 //flip v
2752 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2753 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2754 break;
2755
2756 case 5:
2757 //trans + v flip
2758 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2759 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2760 break;
2761
2762 case 6:
2763 //pivot + v flip
2764 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2765 //return an error, cannot both rotate and pivot
2766 break;
2767
2768 case 8:
2769 //flip h
2770 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
2771 //return an error, cannot both rotate and flip H
2772 break;
2773
2774 case 9:
2775 //trans + h flip
2776 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
2777 //return an error, cannot rotate and flip a trans sprite
2778 break;
2779
2780 case 10:
2781 //flip H and pivot
2782 //return error cannot pivot and h flip
2783 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2784 break;
2785
2786 case 12:
2787 //vh flip
2788 //return an error, cannot rotate and VH flip a trans sprite
2789 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2790 break;
2791
2792 case 13:
2793 //trans + vh flip
2794 //return an error, cannot rotate and VH flip a trans sprite
2795 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2796 break;
2797
2798 case 14:
2799 //pivot and vh flip
2800 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2801 //return error cannot both pivot and vh flip
2802 break;
2803
2804 case 16:
2805 //lit
2806 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2807 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2808 break;
2809
2810 case 18:
2811 //pivot, lit
2812 //return an error, cannot both rotate and pivot
2813 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2814 break;
2815
2816 case 20:
2817 //lit + vflip
2818 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2819 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2820 break;
2821
2822 case 22:
2823 //Pivot, vflip, lit
2824 //return an error, cannot both rotate and pivot
2825 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2826 break;
2827
2828 case 24:
2829 //lit + h flip
2830 //return an error, cannot both rotate and H flip
2831 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
2832 break;
2833
2834 case 26:
2835 //pivot + lit + hflip
2836 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
2837 //return error cannot pivot, lit, and flip
2838 break;
2839
2840 case 28:
2841 //lit + vh flip
2842 //return an error, cannot both rotate and VH flip
2843 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2844 break;
2845
2846 case 32: //gouraud
2847 //Probably not wort supporting.
2848 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2849 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2850 break;
2851
2852 case 0:
2853 //no effect.
2854 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2855 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2856 break;
2857
2858 default:
2859 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2860
2861 }
2862 }
2863 } //end if stretched and masked
2864
2865 else //stretched, not masked
2866 {
2867 if ( rot == 0 ) //if not rotated
2868 {
2869 switch(mode) {
2870 case 1:
2871 //transparent
2872 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2873 draw_trans_sprite(bmp, subBmp, dx, dy);
2874 break;
2875
2876
2877 case 2:
2878 //pivot?
2879 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2880 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2881 //Pivoting requires two more args
2882 break;
2883
2884 case 3:
2885 //pivot + trans
2886 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2887 pivot_sprite_trans(bmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
2888 break;
2889
2890 case 4:
2891 //flip v
2892 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2893 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2894 break;
2895
2896 case 5:
2897 //trans + v flip
2898 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2899 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2900 break;
2901
2902 case 6:
2903 //pivot + v flip
2904 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2905 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2906 break;
2907
2908 case 8:
2909 //vlip h
2910 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2911 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2912 break;
2913
2914 case 9:
2915 //trans + h flip
2916 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2917 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2918 break;
2919
2920 case 10:
2921 //flip H and pivot
2922 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2923 //return error cannot pivot and h flip
2924 break;
2925
2926 case 12:
2927 //vh flip
2928 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2929 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2930 break;
2931
2932 case 13:
2933 //trans + vh flip
2934 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2935 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2936 break;
2937
2938 case 14:
2939 //pivot and vh flip
2940 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2941 //return error cannot both pivot and vh flip
2942 break;
2943
2944 case 16:
2945 //lit
2946 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2947 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2948 break;
2949
2950 case 18:
2951 //pivot, lit
2952 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2953 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2954 break;
2955
2956 case 20:
2957 //lit + v flip
2958 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2959 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2960 break;
2961
2962 case 22:
2963 //Pivot, vflip, lit
2964 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2965 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2966 break;
2967
2968 case 24:
2969 //lit + h flip
2970 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2971 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2972 break;
2973
2974 case 26:
2975 //pivot + lit + hflip
2976 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2977 //return error cannot pivot, lit, and flip
2978 break;
2979
2980 case 28:
2981 //lit + vh flip
2982 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2983 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2984 break;
2985
2986 case 32: //gouraud
2987 //Probably not wort supporting.
2988 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2989 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2990 break;
2991
2992 case 0:
2993 //no effect
2994 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2995 break;
2996
2997
2998 default:
2999 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3000
3001
3002 }
3003 } //end if not rotated
3004
3005 if ( rot != 0 ) //if rotated
3006 {
3007 switch(mode)
3008 {
3009 case 1:
3010 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3011 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3012
3013 break;
3014
3015 case 2:
3016 //pivot?
3017 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3018 //return an error, cannot both rotate and pivot
3019 break;
3020
3021 case 3:
3022 //pivot + trans
3023 //return an error, cannot both rotate and pivot
3024 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3025 break;
3026
3027 case 4:
3028 //flip v
3029 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3030 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3031 break;
3032
3033 case 5:
3034 //trans + v flip
3035 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3036 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3037 break;
3038
3039 case 6:
3040 //pivot + v flip
3041 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3042 //return an error, cannot both rotate and pivot
3043 break;
3044
3045 case 8:
3046 //flip h
3047 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3048 //return an error, cannot both rotate and flip H
3049 break;
3050
3051 case 9:
3052 //trans + h flip
3053 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3054 //return an error, cannot rotate and flip a trans sprite
3055 break;
3056
3057 case 10:
3058 //flip H and pivot
3059 //return error cannot pivot and h flip
3060 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3061 break;
3062
3063 case 12:
3064 //vh flip
3065 //return an error, cannot rotate and VH flip a trans sprite
3066 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3067 break;
3068
3069 case 13:
3070 //trans + vh flip
3071 //return an error, cannot rotate and VH flip a trans sprite
3072 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3073 break;
3074
3075 case 14:
3076 //pivot and vh flip
3077 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3078 //return error cannot both pivot and vh flip
3079 break;
3080
3081 case 16:
3082 //lit
3083 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3084 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3085 break;
3086
3087 case 18:
3088 //pivot, lit
3089 //return an error, cannot both rotate and pivot
3090 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3091 break;
3092
3093 case 20:
3094 //lit + vflip
3095 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3096 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3097 break;
3098
3099 case 22:
3100 //Pivot, vflip, lit
3101 //return an error, cannot both rotate and pivot
3102 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3103 break;
3104
3105 case 24:
3106 //lit + h flip
3107 //return an error, cannot both rotate and H flip
3108 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3109 break;
3110
3111 case 26:
3112 //pivot + lit + hflip
3113 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3114 //return error cannot pivot, lit, and flip
3115 break;
3116
3117 case 28:
3118 //lit + vh flip
3119 //return an error, cannot both rotate and VH flip
3120 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3121 break;
3122
3123 case 32: //gouraud
3124 //Probably not wort supporting.
3125 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3126 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3127 break;
3128
3129 case 0:
3130 //no effect.
3131 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3132 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3133 break;
3134
3135 default:
3136 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3137
3138 }
3139 }
3140
3141 } //end if stretched, but not masked
3142 }
3143 else //not stretched
3144 {
3145
3146 if(masked) //if masked, but not stretched
3147 {
3148
3149 if ( rot == 0 ) //if not rotated
3150 {
3151 switch(mode)
3152 {
3153 case 1:
3154 //transparent
3155 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3156 draw_trans_sprite(bmp, subBmp, dx, dy);
3157 break;
3158
3159
3160 case 2:
3161 //pivot?
3162 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3163 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3164 //Pivoting requires two more args
3165 break;
3166
3167 case 3:
3168 //pivot + trans
3169 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3170 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3171 break;
3172
3173 case 4:
3174 //flip v
3175 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3176 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3177 break;
3178
3179 case 5:
3180 //trans + v flip
3181 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3182 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3183 break;
3184
3185 case 6:
3186 //pivot + v flip
3187 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3188 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3189 break;
3190
3191 case 8:
3192 //vlip h
3193 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3194 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3195 break;
3196
3197 case 9:
3198 //trans + h flip
3199 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3200 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3201 break;
3202
3203 case 10:
3204 //flip H and pivot
3205 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3206 //return error cannot pivot and h flip
3207 break;
3208
3209 case 12:
3210 //vh flip
3211 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3212 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3213 break;
3214
3215 case 13:
3216 //trans + vh flip
3217 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3218 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3219 break;
3220
3221 case 14:
3222 //pivot and vh flip
3223 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3224 //return error cannot both pivot and vh flip
3225 break;
3226
3227 case 16:
3228 //lit
3229 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3230 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3231 break;
3232
3233 case 18:
3234 //pivot, lit
3235 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3236 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3237 break;
3238
3239 case 20:
3240 //lit + v flip
3241 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3242 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3243 break;
3244
3245 case 22:
3246 //Pivot, vflip, lit
3247 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3248 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3249 break;
3250
3251 case 24:
3252 //lit + h flip
3253 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3254 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3255 break;
3256
3257 case 26:
3258 //pivot + lit + hflip
3259 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3260 //return error cannot pivot, lit, and flip
3261 break;
3262
3263 case 28:
3264 //lit + vh flip
3265 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3266 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3267 break;
3268
3269 case 32: //gouraud
3270 //Probably not wort supporting.
3271 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3272 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3273 break;
3274
3275 case 0:
3276 //no effect
3277 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3278 break;
3279
3280
3281 default:
3282 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3283
3284
3285 }
3286 } //end if not rotated
3287
3288 if ( rot != 0 ) //if rotated
3289 {
3290 switch(mode)
3291 {
3292 case 1:
3293 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //transparent
3294 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3295
3296 break;
3297
3298 case 2:
3299 //pivot?
3300 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3301 //return an error, cannot both rotate and pivot
3302 break;
3303
3304 case 3:
3305 //pivot + trans
3306 //return an error, cannot both rotate and pivot
3307 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3308 break;
3309
3310 case 4:
3311 //flip v
3312 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3313 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3314 break;
3315
3316 case 5:
3317 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
3318 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3319 break;
3320
3321 case 6:
3322 //pivot + v flip
3323 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3324 //return an error, cannot both rotate and pivot
3325 break;
3326
3327 case 8:
3328 //flip h
3329 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3330 //return an error, cannot both rotate and flip H
3331 break;
3332
3333 case 9:
3334 //trans + h flip
3335 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3336 //return an error, cannot rotate and flip a trans sprite
3337 break;
3338
3339 case 10:
3340 //flip H and pivot
3341 //return error cannot pivot and h flip
3342 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3343 break;
3344
3345 case 12:
3346 //vh flip
3347 //return an error, cannot rotate and VH flip a trans sprite
3348 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3349 break;
3350
3351 case 13:
3352 //trans + vh flip
3353 //return an error, cannot rotate and VH flip a trans sprite
3354 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3355 break;
3356
3357 case 14:
3358 //pivot and vh flip
3359 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3360 //return error cannot both pivot and vh flip
3361 break;
3362
3363 case 16:
3364 //lit
3365 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3366 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3367 break;
3368
3369 case 18:
3370 //pivot, lit
3371 //return an error, cannot both rotate and pivot
3372 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3373 break;
3374
3375 case 20:
3376 //lit + vflip
3377 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3378 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3379 break;
3380
3381 case 22:
3382 //Pivot, vflip, lit
3383 //return an error, cannot both rotate and pivot
3384 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3385 break;
3386
3387 case 24:
3388 //lit + h flip
3389 //return an error, cannot both rotate and H flip
3390 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3391 break;
3392
3393 case 26:
3394 //pivot + lit + hflip
3395 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3396 //return error cannot pivot, lit, and flip
3397 break;
3398
3399 case 28:
3400 //lit + vh flip
3401 //return an error, cannot both rotate and VH flip
3402 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3403 break;
3404
3405 case 32: //gouraud
3406 //Probably not wort supporting.
3407 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3408 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3409 break;
3410
3411 case 0:
3412 //no effect.
3413 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3414 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3415 break;
3416
3417 default:
3418 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3419
3420 }
3421 } //end rtated, masked
3422 } //end if masked
3423
3424 else //not masked, and not stretched; just blit
3425 {
3426
3427 if ( rot == 0 ) //if not rotated
3428 {
3429 switch(mode)
3430 {
3431 case 1:
3432 //transparent
3433 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3434 draw_trans_sprite(bmp, subBmp, dx, dy);
3435 break;
3436
3437
3438 case 2:
3439 //pivot?
3440 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3441 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3442 //Pivoting requires two more args
3443 break;
3444
3445 case 3:
3446 //pivot + trans
3447 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3448 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3449 break;
3450
3451 case 4:
3452 //flip v
3453 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3454 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3455 break;
3456
3457 case 5:
3458 //trans + v flip
3459 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3460 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3461 break;
3462
3463 case 6:
3464 //pivot + v flip
3465 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3466 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3467 break;
3468
3469 case 8:
3470 //vlip h
3471 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3472 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3473 break;
3474
3475 case 9:
3476 //trans + h flip
3477 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3478 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3479 break;
3480
3481 case 10:
3482 //flip H and pivot
3483 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3484 //return error cannot pivot and h flip
3485 break;
3486
3487 case 12:
3488 //vh flip
3489 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3490 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3491 break;
3492
3493 case 13:
3494 //trans + vh flip
3495 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3496 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3497 break;
3498
3499 case 14:
3500 //pivot and vh flip
3501 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3502 //return error cannot both pivot and vh flip
3503 break;
3504
3505 case 16:
3506 //lit
3507 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3508 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3509 break;
3510
3511 case 18:
3512 //pivot, lit
3513 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3514 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3515 break;
3516
3517 case 20:
3518 //lit + v flip
3519 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3520 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3521 break;
3522
3523 case 22:
3524 //Pivot, vflip, lit
3525 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3526 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3527 break;
3528
3529 case 24:
3530 //lit + h flip
3531 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3532 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3533 break;
3534
3535 case 26:
3536 //pivot + lit + hflip
3537 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3538 //return error cannot pivot, lit, and flip
3539 break;
3540
3541 case 28:
3542 //lit + vh flip
3543 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3544 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3545 break;
3546
3547 case 32: //gouraud
3548 //Probably not wort supporting.
3549 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3550 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3551 break;
3552
3553 case 0:
3554 //no effect
3555 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3556 break;
3557
3558
3559 default:
3560 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3561
3562
3563 }
3564 } //end if not rotated
3565
3566 if ( rot != 0 ) //if rotated
3567 {
3568 switch(mode)
3569 {
3570 case 1:
3571 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);//transparent
3572 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3573
3574 break;
3575
3576 case 2:
3577 //pivot?
3578 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3579 //return an error, cannot both rotate and pivot
3580 break;
3581
3582 case 3:
3583 //pivot + trans
3584 //return an error, cannot both rotate and pivot
3585 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3586 break;
3587
3588 case 4:
3589 //flip v
3590 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3591 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3592 break;
3593
3594 case 5:
3595 //trans + v flip
3596 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3597 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3598 break;
3599
3600 case 6:
3601 //pivot + v flip
3602 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3603 //return an error, cannot both rotate and pivot
3604 break;
3605
3606 case 8:
3607 //flip h
3608 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3609 //return an error, cannot both rotate and flip H
3610 break;
3611
3612 case 9:
3613 //trans + h flip
3614 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3615 //return an error, cannot rotate and flip a trans sprite
3616 break;
3617
3618 case 10:
3619 //flip H and pivot
3620 //return error cannot pivot and h flip
3621 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3622 break;
3623
3624 case 12:
3625 //vh flip
3626 //return an error, cannot rotate and VH flip a trans sprite
3627 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3628 break;
3629
3630 case 13:
3631 //trans + vh flip
3632 //return an error, cannot rotate and VH flip a trans sprite
3633 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3634 break;
3635
3636 case 14:
3637 //pivot and vh flip
3638 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3639 //return error cannot both pivot and vh flip
3640 break;
3641
3642 case 16:
3643 //lit
3644 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3645 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3646 break;
3647
3648 case 18:
3649 //pivot, lit
3650 //return an error, cannot both rotate and pivot
3651 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3652 break;
3653
3654 case 20:
3655 //lit + vflip
3656 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3657 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3658 break;
3659
3660 case 22:
3661 //Pivot, vflip, lit
3662 //return an error, cannot both rotate and pivot
3663 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3664 break;
3665
3666 case 24:
3667 //lit + h flip
3668 //return an error, cannot both rotate and H flip
3669 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3670 break;
3671
3672 case 26:
3673 //pivot + lit + hflip
3674 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3675 //return error cannot pivot, lit, and flip
3676 break;
3677
3678 case 28:
3679 //lit + vh flip
3680 //return an error, cannot both rotate and VH flip
3681 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3682 break;
3683
3684 case 32: //gouraud
3685 //Probably not wort supporting.
3686 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3687 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3688 break;
3689
3690 case 0:
3691 //no effect.
3692 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3693 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3694 break;
3695
3696 default:
3697 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3698
3699 }
3700 } //end if rotated
3701 } //end if not masked
3702 } //end if not stretched
3703
3704 //cleanup
3705 if(subBmp)
3706 {
3707 script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
3708 }
3709 }
3710
3711
3712 void do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3713 {
3714 //sdci[1]=layer
3715 //sdci[2]=pos[12]
3716 //sdci[3]=uv[8]
3717 //sdci[4]=color[4]
3718 //sdci[5]=size[2]
3719 //sdci[6]=flip
3720 //sdci[7]=tile/combo
3721 //sdci[8]=polytype
3722
3723 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3724
3725 if(!v_ptr)
3726 {
3727 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
3728 return;
3729 }
3730
3731 std::vector<int32_t> &v = *v_ptr;
3732
3733 if(v.empty())
3734 return;
3735
3736 int32_t* pos = &v[0];
3737 int32_t* uv = &v[12];
3738 int32_t* col = &v[20];
3739 int32_t* size = &v[24];
3740
3741 int32_t w = size[0]; //magic numerical constants... yuck.
3742 int32_t h = size[1];
3743 int32_t flip = (sdci[6]/10000)&3;
3744 int32_t tile = sdci[7]/10000;
3745 int32_t polytype = sdci[8]/10000;
3746
3747 polytype = vbound(polytype, 0, 14);
3748
3749 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3750 {
3751 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3752 return; //non power of two error
3753 }
3754
3755 int32_t tex_width = w*16;
3756 int32_t tex_height = h*16;
3757
3758 bool mustDestroyBmp = false;
3759 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3760
3761 if(!tex)
3762 {
3763 mustDestroyBmp = true;
3764 tex = create_bitmap_ex(8, tex_width, tex_height);
3765 clear_bitmap(tex);
3766 }
3767
3768 if(tile > 0) // TILE
3769 {
3770 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3771 }
3772 else // COMBO
3773 {
3774 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3775 const int32_t tiletodraw = combo_tile(c, 0, 0);
3776 flip = flip ^ c.flip;
3777
3778 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3779 }
3780
3781 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3782 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3783 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3784 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
3785
3786 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
3787
3788 if(mustDestroyBmp)
3789 destroy_bitmap(tex);
3790
3791 }
3792
3793
3794
3795 void do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3796 {
3797 //sdci[1]=layer
3798 //sdci[2]=pos[9]
3799 //sdci[3]=uv[6]
3800 //sdci[4]=color[3]
3801 //sdci[5]=size[2]
3802 //sdci[6]=flip
3803 //sdci[7]=tile/combo
3804 //sdci[8]=polytype
3805
3806 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3807
3808 if(!v_ptr)
3809 {
3810 al_trace("Triange3d: Vector pointer is null! Internal error. \n");
3811 return;
3812 }
3813
3814 std::vector<int32_t> &v = *v_ptr;
3815
3816 if(v.empty())
3817 return;
3818
3819 int32_t* pos = &v[0];
3820 int32_t* uv = &v[9];
3821 int32_t* col = &v[15];
3822 int32_t* size = &v[18];
3823
3824 int32_t w = size[0]; //magic numerical constants... yuck.
3825 int32_t h = size[1];
3826 int32_t flip = (sdci[6]/10000)&3;
3827 int32_t tile = sdci[7]/10000;
3828 int32_t polytype = sdci[8]/10000;
3829
3830 polytype = vbound(polytype, 0, 14);
3831
3832 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3833 {
3834 Z_message("Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3835 return; //non power of two error
3836 }
3837
3838 int32_t tex_width = w*16;
3839 int32_t tex_height = h*16;
3840
3841 bool mustDestroyBmp = false;
3842 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3843
3844 if(!tex)
3845 {
3846 mustDestroyBmp = true;
3847 tex = create_bitmap_ex(8, tex_width, tex_height);
3848 clear_bitmap(tex);
3849 }
3850
3851 if(tile > 0) // TILE
3852 {
3853 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3854 }
3855 else // COMBO
3856 {
3857 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3858 const int32_t tiletodraw = combo_tile(c, 0, 0);
3859 flip = flip ^ c.flip;
3860
3861 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3862 }
3863
3864 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3865 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3866 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3867
3868 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
3869
3870 if(mustDestroyBmp)
3871 destroy_bitmap(tex);
3872
3873 }
3874
3875 7818 void bmp_do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3876 {
3877 //Z_scripterrlog("rect sdci[13] is: %d\n", sdci[13]);
3878 //sdci[1]=layer
3879 //sdci[2]=x
3880 //sdci[3]=y
3881 //sdci[4]=x2
3882 //sdci[5]=y2
3883 //sdci[6]=color
3884 //sdci[7]=scale factor
3885 //sdci[8]=rotation anchor x
3886 //sdci[9]=rotation anchor y
3887 //sdci[10]=rotation angle
3888 //sdci[11]=fill
3889 //sdci[12]=opacity
3890 //sdci[17] Bitmap Pointer
3891
1/2
✓ Branch 0 taken 7818 times.
✗ Branch 1 not taken.
7818 if(sdci[7]==0) //scale
3892 {
3893 return;
3894 }
3895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7818 times.
7818 if ( sdci[17] <= 0 )
3896 {
3897 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
3898 return;
3899 }
3900 7818 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
3901
1/2
✓ Branch 0 taken 7818 times.
✗ Branch 1 not taken.
7818 if ( refbmp == NULL ) return;
3902
3903
2/4
✓ Branch 0 taken 7818 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7818 times.
7818 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
3904
3905 7818 int32_t x1=sdci[2]/10000;
3906 7818 int32_t y1=sdci[3]/10000;
3907 7818 int32_t x2=sdci[4]/10000;
3908 7818 int32_t y2=sdci[5]/10000;
3909
3910
3911
2/2
✓ Branch 0 taken 7814 times.
✓ Branch 1 taken 4 times.
7818 if(x1>x2)
3912 {
3913 4 zc_swap(x1,x2);
3914 4 }
3915
3916
2/2
✓ Branch 0 taken 7814 times.
✓ Branch 1 taken 4 times.
7818 if(y1>y2)
3917 {
3918 4 zc_swap(y1,y2);
3919 4 }
3920
3921
1/2
✓ Branch 0 taken 7818 times.
✗ Branch 1 not taken.
7818 if(sdci[7] != 10000)
3922 {
3923 int32_t w=x2-x1+1;
3924 int32_t h=y2-y1+1;
3925 int32_t w2=(w*sdci[7])/10000;
3926 int32_t h2=(h*sdci[7])/10000;
3927 x1=x1-((w2-w)/2);
3928 x2=x2+((w2-w)/2);
3929 y1=y1-((h2-h)/2);
3930 y2=y2+((h2-h)/2);
3931 }
3932
3933 7818 int32_t color=sdci[6]/10000;
3934
3935
2/2
✓ Branch 0 taken 7690 times.
✓ Branch 1 taken 128 times.
7818 if(sdci[12]/10000<=127) //translucent
3936 {
3937 128 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
3938 128 }
3939
3940
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 7722 times.
7818 if(sdci[10]==0) //no rotation
3941 {
3942
2/2
✓ Branch 0 taken 7710 times.
✓ Branch 1 taken 12 times.
7722 if(sdci[11]) //filled
3943 {
3944 7710 rectfill(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3945 7710 }
3946 else //outline
3947 {
3948 12 rect(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3949 }
3950 7722 }
3951 else //rotate
3952 {
3953 int32_t xy[16];
3954 96 int32_t rx=sdci[8]/10000;
3955 96 int32_t ry=sdci[9]/10000;
3956 96 fixed ra1=itofix(sdci[10]%10000)/10000;
3957 96 fixed ra2=itofix(sdci[10]/10000);
3958 96 fixed ra=ra1+ra2;
3959 96 ra = (ra/360)*256;
3960
3961 96 fixed fcosa = fixcos(ra);
3962 96 fixed fsina = fixsin(ra);
3963
3964 96 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
3965 96 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
3966 96 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
3967 96 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
3968 96 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
3969 96 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
3970 96 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
3971 96 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
3972 96 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
3973 96 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
3974 96 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
3975 96 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
3976 96 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
3977 96 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
3978 96 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
3979 96 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
3980
3981
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(sdci[11]) //filled
3982 {
3983 96 polygon(refbmp, 4, xy, color);
3984 96 }
3985 else //outline
3986 {
3987 line(refbmp, xy[0], xy[1], xy[10], xy[11], color);
3988 line(refbmp, xy[2], xy[3], xy[12], xy[13], color);
3989 line(refbmp, xy[4], xy[5], xy[14], xy[15], color);
3990 line(refbmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
3991 }
3992 }
3993
3994 7818 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
3995 7818 }
3996
3997 void bmp_do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3998 {
3999 //sdci[1]=layer
4000 //sdci[2]=x
4001 //sdci[3]=y
4002 //sdci[4]=tile
4003 //sdci[5]=cset
4004 //sdci[6]=width
4005 //sdci[7]=height
4006 //sdci[8]=overlay
4007 //sdci[9]=opacity
4008
4009 if ( sdci[17] <= 0 )
4010 {
4011 Z_scripterrlog("bitmap->DrawFrame() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4012 return;
4013 }
4014 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4015 if ( refbmp == NULL ) return;
4016
4017 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4018
4019 int32_t x=sdci[2]/10000;
4020 int32_t y=sdci[3]/10000;
4021
4022 int32_t tile=sdci[4]/10000;
4023 int32_t cs=sdci[5]/10000;
4024 int32_t w=sdci[6]/10000;
4025 int32_t h=sdci[7]/10000;
4026 bool overlay=sdci[8];
4027 bool trans=(sdci[9]/10000<=127);
4028
4029 frame2x2(refbmp, &QMisc, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
4030 }
4031
4032
4033 1480 void bmp_do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4034 {
4035 //sdci[1]=layer
4036 //sdci[2]=x
4037 //sdci[3]=y
4038 //sdci[4]=radius
4039 //sdci[5]=color
4040 //sdci[6]=scale factor
4041 //sdci[7]=rotation anchor x
4042 //sdci[8]=rotation anchor y
4043 //sdci[9]=rotation angle
4044 //sdci[10]=fill
4045 //sdci[11]=opacity
4046 //sdci[17] Bitmap Pointer
4047
1/2
✓ Branch 0 taken 1480 times.
✗ Branch 1 not taken.
1480 if(sdci[6]==0) //scale
4048 {
4049 return;
4050 }
4051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1480 times.
1480 if ( sdci[17] <= 0 )
4052 {
4053 Z_scripterrlog("bitmap->Circle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4054 return;
4055 }
4056 1480 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4057
1/2
✓ Branch 0 taken 1480 times.
✗ Branch 1 not taken.
1480 if ( refbmp == NULL ) return;
4058
4059
2/4
✓ Branch 0 taken 1480 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1480 times.
1480 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4060
4061 1480 int32_t x1=sdci[2]/10000;
4062 1480 int32_t y1=sdci[3]/10000;
4063 1480 qword r=sdci[4];
4064
4065
1/2
✓ Branch 0 taken 1480 times.
✗ Branch 1 not taken.
1480 if(sdci[6] != 10000)
4066 {
4067 r*=sdci[6];
4068 r/=10000;
4069 }
4070
4071 1480 r/=10000;
4072 1480 int32_t color=sdci[5]/10000;
4073
4074
1/2
✓ Branch 0 taken 1480 times.
✗ Branch 1 not taken.
1480 if(sdci[11]/10000<=127) //translucent
4075 {
4076 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4077 }
4078
4079
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1480 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1480 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
4080 {
4081 int32_t xy[2];
4082 int32_t rx=sdci[7]/10000;
4083 int32_t ry=sdci[8]/10000;
4084 fixed ra1=itofix(sdci[9]%10000)/10000;
4085 fixed ra2=itofix(sdci[9]/10000);
4086 fixed ra=ra1+ra2;
4087 ra = (ra/360)*256;
4088
4089 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4090 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4091 x1=xy[0];
4092 y1=xy[1];
4093 }
4094
4095
1/2
✓ Branch 0 taken 1480 times.
✗ Branch 1 not taken.
1480 if(sdci[10]) //filled
4096 {
4097 1480 circlefill(refbmp, x1+xoffset, y1+yoffset, r, color);
4098 1480 }
4099 else //outline
4100 {
4101 circle(refbmp, x1+xoffset, y1+yoffset, r, color);
4102 }
4103
4104 1480 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4105 1480 }
4106
4107
4108 void bmp_do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4109 {
4110 //sdci[1]=layer
4111 //sdci[2]=x
4112 //sdci[3]=y
4113 //sdci[4]=radius
4114 //sdci[5]=start angle
4115 //sdci[6]=end angle
4116 //sdci[7]=color
4117 //sdci[8]=scale factor
4118 //sdci[9]=rotation anchor x
4119 //sdci[10]=rotation anchor y
4120 //sdci[11]=rotation angle
4121 //sdci[12]=closed
4122 //sdci[13]=fill
4123 //sdci[14]=opacity
4124 //sdci[17] Bitmap Pointer
4125
4126 if(sdci[8]==0) //scale
4127 {
4128 return;
4129 }
4130 if ( sdci[17] <= 0 )
4131 {
4132 Z_scripterrlog("bitmap->Arc() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4133 return;
4134 }
4135 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4136 if ( refbmp == NULL ) return;
4137
4138 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4139
4140 int32_t cx=sdci[2]/10000;
4141 int32_t cy=sdci[3]/10000;
4142 qword r=sdci[4];
4143
4144 if(sdci[8] != 10000)
4145 {
4146 r*=sdci[8];
4147 r/=10000;
4148 }
4149
4150 r/=10000;
4151
4152 int32_t color=sdci[7]/10000;
4153
4154 fixed ra1=itofix(sdci[11]%10000)/10000;
4155 fixed ra2=itofix(sdci[11]/10000);
4156 fixed ra=ra1+ra2;
4157 ra = (ra/360)*256;
4158
4159
4160 fixed a1=itofix(sdci[5]%10000)/10000;
4161 fixed a2=itofix(sdci[5]/10000);
4162 fixed sa=a1+a2;
4163 sa = (sa/360)*256;
4164
4165 a1=itofix(sdci[6]%10000)/10000;
4166 a2=itofix(sdci[6]/10000);
4167 fixed ea=a1+a2;
4168 ea = (ea/360)*256;
4169
4170 if(sdci[11]!=0) //rotation
4171 {
4172 int32_t rx=sdci[9]/10000;
4173 int32_t ry=sdci[10]/10000;
4174
4175 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
4176 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
4177 ea-=ra;
4178 sa-=ra;
4179 }
4180
4181 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
4182 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
4183
4184 if(sdci[12]) //closed
4185 {
4186 if(sdci[13]) //filled
4187 {
4188 clear_bitmap(prim_bmp);
4189 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4190 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4191 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4192 int fillx = zc_max(0,fx)+xoffset;
4193 int filly = zc_max(0,fy)+yoffset;
4194 zprint2("bitmap->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
4195 floodfill(prim_bmp, fillx, filly, color);
4196
4197 if(sdci[14]/10000<=127) //translucent
4198 {
4199 draw_trans_sprite(refbmp, prim_bmp, 0,0);
4200 }
4201 else
4202 {
4203 draw_sprite(refbmp, prim_bmp, 0,0);
4204 }
4205 }
4206 else
4207 {
4208 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4209 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4210 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4211 }
4212 }
4213 else
4214 {
4215 if(sdci[14]/10000<=127) //translucent
4216 {
4217 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4218 }
4219
4220 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4221 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4222 }
4223 }
4224
4225
4226 502 void bmp_do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4227 {
4228 //sdci[1]=layer
4229 //sdci[2]=x
4230 //sdci[3]=y
4231 //sdci[4]=radiusx
4232 //sdci[5]=radiusy
4233 //sdci[6]=color
4234 //sdci[7]=scale factor
4235 //sdci[8]=rotation anchor x
4236 //sdci[9]=rotation anchor y
4237 //sdci[10]=rotation angle
4238 //sdci[11]=fill
4239 //sdci[12]=opacity
4240 //sdci[17] Bitmap Pointer
4241
4242
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if(sdci[7]==0) //scale
4243 {
4244 return;
4245 }
4246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 502 times.
502 if ( sdci[17] <= 0 )
4247 {
4248 Z_scripterrlog("bitmap->Ellipse() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4249 return;
4250 }
4251 502 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4252
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if ( refbmp == NULL ) return;
4253
4254 502 int32_t x1=sdci[2]/10000;
4255 502 int32_t y1=sdci[3]/10000;
4256 502 int32_t radx=sdci[4]/10000;
4257 502 radx*=sdci[7]/10000;
4258 502 int32_t rady=sdci[5]/10000;
4259 502 rady*=sdci[7]/10000;
4260 502 int32_t color=sdci[6]/10000;
4261 502 float rotation = sdci[10]/10000;
4262
4263 502 int32_t rx=sdci[8]/10000;
4264 502 int32_t ry=sdci[9]/10000;
4265 502 fixed ra1=itofix(sdci[10]%10000)/10000;
4266 502 fixed ra2=itofix(sdci[10]/10000);
4267 502 fixed ra=ra1+ra2;
4268 502 ra = (ra/360)*256;
4269
4270
2/4
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 502 times.
✗ Branch 3 not taken.
502 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4271
4272 int32_t xy[2];
4273 502 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4274 502 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4275 502 x1=xy[0];
4276 502 y1=xy[1];
4277
4278
6/8
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 494 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 494 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 494 times.
502 if(radx<1||rady<1||radx>255||rady>255) return;
4279
4280 494 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
4281
4282
2/4
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 494 times.
494 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4283
4284
1/2
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
494 if(sdci[11]) //filled
4285 {
4286
4287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 494 times.
494 if(sdci[12]/10000<128) //translucent
4288 {
4289 clear_bitmap(prim_bmp);
4290 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4291 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4292 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4293 }
4294 else // no opacity
4295 {
4296
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4297 494 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4298 }
4299 494 }
4300 else //not filled
4301 {
4302 if(sdci[12]/10000<128) //translucent
4303 {
4304 clear_bitmap(prim_bmp);
4305 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4306 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4307 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4308 }
4309 else // no opacity
4310 {
4311 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4312 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4313 }
4314 }
4315
4316 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
4317 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
4318 // the ellipse, but it shouldn't be used anyway.
4319
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 if(color==0)
4320 {
4321 // This is very slow, so check the smallest possible square
4322
3/6
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✓ Branch 4 taken 62 times.
✗ Branch 5 not taken.
62 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
4323
3/6
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✓ Branch 4 taken 62 times.
✗ Branch 5 not taken.
62 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
4324
4325
6/8
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4430 times.
✓ Branch 7 taken 62 times.
4492 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
4326
6/8
✓ Branch 0 taken 4430 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3052 times.
✓ Branch 3 taken 1378 times.
✓ Branch 4 taken 1378 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 467774 times.
✓ Branch 7 taken 4430 times.
472204 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
4327
2/2
✓ Branch 0 taken 238992 times.
✓ Branch 1 taken 228782 times.
696556 if(getpixel(refbmp, x, y)==255)
4328 233212 putpixel(refbmp, x, y, 0);
4329 62 }
4330
4331 494 script_drawing_commands.ReleaseSubBitmap(bitty);
4332 502 }
4333
4334
4335 144 void bmp_do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4336 {
4337 //sdci[1]=layer
4338 //sdci[2]=x
4339 //sdci[3]=y
4340 //sdci[4]=x2
4341 //sdci[5]=y2
4342 //sdci[6]=color
4343 //sdci[7]=scale factor
4344 //sdci[8]=rotation anchor x
4345 //sdci[9]=rotation anchor y
4346 //sdci[10]=rotation angle
4347 //sdci[11]=opacity
4348 //sdci[17] Bitmap Pointer
4349
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7]==0) //scale
4350 {
4351 return;
4352 }
4353
4354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 144 times.
144 if ( sdci[17] <= 0 )
4355 {
4356 Z_scripterrlog("bitmap->Line() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4357 return;
4358 }
4359
4360 144 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4361
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if ( refbmp == NULL ) return;
4362
4363 144 int32_t x1=sdci[2]/10000;
4364 144 int32_t y1=sdci[3]/10000;
4365 144 int32_t x2=sdci[4]/10000;
4366 144 int32_t y2=sdci[5]/10000;
4367
4368
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7] != 10000)
4369 {
4370 int32_t w=x2-x1+1;
4371 int32_t h=y2-y1+1;
4372 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
4373 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
4374 x1=x1-((w2-w)/2);
4375 x2=x2+((w2-w)/2);
4376 y1=y1-((h2-h)/2);
4377 y2=y2+((h2-h)/2);
4378 }
4379
4380 144 int32_t color=sdci[6]/10000;
4381
4382
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
144 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4383
4384
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[11]/10000<=127) //translucent
4385 {
4386 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4387 }
4388
4389
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[10]!=0) //rotation
4390 {
4391 int32_t xy[4];
4392 int32_t rx=sdci[8]/10000;
4393 int32_t ry=sdci[9]/10000;
4394 fixed ra1=itofix(sdci[10]%10000)/10000;
4395 fixed ra2=itofix(sdci[10]/10000);
4396 fixed ra=ra1+ra2;
4397
4398 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4399 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4400 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
4401 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
4402 x1=xy[0];
4403 y1=xy[1];
4404 x2=xy[2];
4405 y2=xy[3];
4406 }
4407
4408 144 line(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4409 144 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4410 144 }
4411
4412
4413 void bmp_do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4414 {
4415 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
4416 //sdci[17] Bitmap Pointer
4417
4418 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
4419 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
4420 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
4421 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
4422 };
4423
4424 if(sdci[11]/10000 < 128) //translucent
4425 {
4426 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4427 }
4428
4429 if ( sdci[17] <= 0 )
4430 {
4431 Z_scripterrlog("bitmap->Spline() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4432 return;
4433 }
4434
4435 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4436 if ( refbmp == NULL ) return;
4437
4438 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4439
4440 spline(refbmp, points, sdci[10]/10000);
4441
4442 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4443 }
4444
4445
4446 80910 void bmp_do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4447 {
4448 //sdci[1]=layer
4449 //sdci[2]=x
4450 //sdci[3]=y
4451 //sdci[4]=color
4452 //sdci[5]=rotation anchor x
4453 //sdci[6]=rotation anchor y
4454 //sdci[7]=rotation angle
4455 //sdci[8]=opacity
4456 //sdci[17] Bitmap Pointer
4457 80910 int32_t x1=sdci[2]/10000;
4458 80910 int32_t y1=sdci[3]/10000;
4459 80910 int32_t color=sdci[4]/10000;
4460
4461
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if(sdci[8]/10000<=127) //translucent
4462 {
4463 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4464 }
4465
4466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if ( sdci[17] <= 0 )
4467 {
4468 Z_scripterrlog("bitmap->PutPixel() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4469 return;
4470 }
4471
4472 80910 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4473
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if ( refbmp == NULL ) return;
4474
4475
2/4
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80910 times.
✗ Branch 3 not taken.
80910 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4476
4477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if(sdci[7]!=0) //rotation
4478 {
4479 int32_t xy[2];
4480 int32_t rx=sdci[5]/10000;
4481 int32_t ry=sdci[6]/10000;
4482 fixed ra1=itofix(sdci[7]%10000)/10000;
4483 fixed ra2=itofix(sdci[7]/10000);
4484 fixed ra=ra1+ra2;
4485
4486 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4487 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4488 x1=xy[0];
4489 y1=xy[1];
4490 }
4491
4492 80910 putpixel(refbmp, x1+xoffset, y1+yoffset, color);
4493 80910 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4494 80910 }
4495
4496
4497 59428 void bmp_do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4498 {
4499 //sdci[1]=layer
4500 //sdci[2]=x
4501 //sdci[3]=y
4502 //sdci[4]=tile
4503 //sdci[5]=tile width
4504 //sdci[6]=tile height
4505 //sdci[7]=color (cset)
4506 //sdci[8]=scale x
4507 //sdci[9]=scale y
4508 //sdci[10]=rotation anchor x
4509 //sdci[11]=rotation anchor y
4510 //sdci[12]=rotation angle
4511 //sdci[13]=flip
4512 //sdci[14]=transparency
4513 //sdci[15]=opacity
4514 //sdci[17] Bitmap Pointer
4515
4516 59428 int32_t w = sdci[5]/10000;
4517 59428 int32_t h = sdci[6]/10000;
4518
4519
4/8
✓ Branch 0 taken 59428 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59428 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 59428 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 59428 times.
59428 if(w < 1 || h < 1 || h > 20 || w > 20)
4520 {
4521 return;
4522 }
4523
4524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59428 times.
59428 if ( sdci[17] <= 0 )
4525 {
4526 Z_scripterrlog("bitmap->DrawTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4527 return;
4528 }
4529
4530 59428 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59428 times.
59428 if ( refbmp == NULL ) return;
4532
4533 59428 int32_t xscale=sdci[8]/10000;
4534 59428 int32_t yscale=sdci[9]/10000;
4535 59428 int32_t rx = sdci[10]/10000;
4536 59428 int32_t ry = sdci[11]/10000;
4537 59428 float rotation=sdci[12]/10000;
4538 59428 int32_t flip=(sdci[13]/10000)&3;
4539 59428 bool transparency=sdci[14]!=0;
4540 59428 int32_t opacity=sdci[15]/10000;
4541 59428 int32_t color=sdci[7]/10000;
4542
4543 59428 int32_t x1=sdci[2]/10000;
4544 59428 int32_t y1=sdci[3]/10000;
4545
4546
4547 //don't scale if it's not safe to do so
4548 59428 bool canscale = true;
4549
4550
2/4
✓ Branch 0 taken 59428 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59428 times.
59428 if(xscale==0||yscale==0)
4551 {
4552 return;
4553 }
4554
4555
3/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58522 times.
✓ Branch 2 taken 906 times.
✗ Branch 3 not taken.
59428 if(xscale<0||yscale<0)
4556 58522 canscale = false; //default size
4557
4558
2/4
✓ Branch 0 taken 59428 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59428 times.
59428 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4559
4560
4/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58522 times.
✓ Branch 2 taken 4608 times.
✓ Branch 3 taken 53914 times.
59428 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4561 {
4562 5514 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
4563
4564
1/2
✓ Branch 0 taken 5514 times.
✗ Branch 1 not taken.
5514 if(transparency) //transparency
4565 {
4566 5514 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4567 5514 }
4568 else //no transparency
4569 {
4570 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4571 }
4572
4573
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 906 times.
5514 if(rotation != 0)
4574 {
4575 //low negative values indicate no anchor-point rotation
4576
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4608 if(rx>-777||ry>-777)
4577 {
4578 int32_t xy[2];
4579 4608 fixed ra1=itofix(sdci[12]%10000)/10000;
4580 4608 fixed ra2=itofix(sdci[12]/10000);
4581 4608 fixed ra=ra1+ra2;
4582 4608 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4583 4608 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4584 4608 x1=xy[0];
4585 4608 y1=xy[1];
4586 4608 }
4587
4588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(canscale) //scale first
4589 {
4590 //damnit all, .. fixme.
4591 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4592 clear_bitmap(tempbit);
4593
4594 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4595
4596 if(opacity < 128)
4597 {
4598 clear_bitmap(prim_bmp);
4599 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4600 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
4601 }
4602 else
4603 {
4604 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4605 }
4606
4607 destroy_bitmap(tempbit);
4608 }
4609 else //no scale
4610 {
4611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(opacity < 128)
4612 {
4613 clear_bitmap(prim_bmp);
4614 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4615 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4616 }
4617 else
4618 {
4619 4608 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4620 }
4621 }
4622 4608 }
4623 else //scale only
4624 {
4625
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if(canscale)
4626 {
4627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(opacity<128)
4628 {
4629 clear_bitmap(prim_bmp);
4630 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4631 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4632 }
4633 else
4634 {
4635 906 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4636 }
4637 906 }
4638 else //error -do not scale
4639 {
4640 if(opacity<128)
4641 {
4642 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4643 }
4644 else
4645 {
4646 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4647 }
4648 }
4649 }
4650
4651 5514 script_drawing_commands.ReleaseSubBitmap(pbitty);
4652
4653 5514 }
4654 else // no scale or rotation
4655 {
4656
2/2
✓ Branch 0 taken 45760 times.
✓ Branch 1 taken 8154 times.
53914 if(transparency)
4657 {
4658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45760 times.
45760 if(opacity<=127)
4659 TileHelper::OverTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4660 else
4661 45760 TileHelper::OverTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4662 45760 }
4663 else
4664 {
4665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8154 times.
8154 if(opacity<=127)
4666 TileHelper::PutTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4667 else
4668 8154 TileHelper::OldPutTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4669 }
4670 }
4671 59428 }
4672
4673 void bmp_do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4674 {
4675 //sdci[1]=layer
4676 //sdci[2]=x
4677 //sdci[3]=y
4678 //sdci[4]=tile
4679 //sdci[5]=tile width
4680 //sdci[6]=tile height
4681 //sdci[7]=flip
4682 //sdci[17] Bitmap Pointer
4683
4684 int32_t w = sdci[5]/10000;
4685 int32_t h = sdci[6]/10000;
4686
4687 if(w < 1 || h < 1 || h > 20 || w > 20)
4688 {
4689 return;
4690 }
4691
4692 if ( sdci[17] <= 0 )
4693 {
4694 Z_scripterrlog("bitmap->DrawTileCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4695 return;
4696 }
4697
4698 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4699 if ( refbmp == NULL ) return;
4700
4701 int32_t flip=(sdci[7]/10000)&3;
4702
4703 int32_t x1=sdci[2]/10000;
4704 int32_t y1=sdci[3]/10000;
4705
4706 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4707
4708 TileHelper::OverTileCloaked(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
4709 }
4710
4711
4712 824 void bmp_do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4713 {
4714 //sdci[1]=layer
4715 //sdci[2]=x
4716 //sdci[3]=y
4717 //sdci[4]=combo
4718 //sdci[5]=tile width
4719 //sdci[6]=tile height
4720 //sdci[7]=color (cset)
4721 //sdci[8]=scale x
4722 //sdci[9]=scale y
4723 //sdci[10]=rotation anchor x
4724 //sdci[11]=rotation anchor y
4725 //sdci[12]=rotation angle
4726 //sdci[13]=frame
4727 //sdci[14]=flip
4728 //sdci[15]=transparency
4729 //sdci[16]=opacity
4730 //sdci[17] Bitmap Pointer
4731 824 int32_t w = sdci[5]/10000;
4732 824 int32_t h = sdci[6]/10000;
4733
4734
4/8
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 824 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 824 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 824 times.
824 if(w<1||h<1||h>20||w>20)
4735 {
4736 return;
4737 }
4738
4739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if ( sdci[17] <= 0 )
4740 {
4741 Z_scripterrlog("bitmap->DrawCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4742 return;
4743 }
4744
4745 824 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4746
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if ( refbmp == NULL ) return;
4747 824 int32_t cmb = (sdci[4]/10000);
4748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if((unsigned)cmb >= MAXCOMBOS)
4749 {
4750 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4751 return;
4752 }
4753
4754 824 int32_t xscale=sdci[8]/10000;
4755 824 int32_t yscale=sdci[9]/10000;
4756 824 int32_t rx = sdci[10]/10000; //these work now
4757 824 int32_t ry = sdci[11]/10000; //these work now
4758 824 float rotation=sdci[12]/10000;
4759
4760 824 bool transparency=sdci[15]!=0;
4761 824 int32_t opacity=sdci[16]/10000;
4762 824 int32_t color=sdci[7]/10000;
4763 824 int32_t x1=sdci[2]/10000;
4764 824 int32_t y1=sdci[3]/10000;
4765
4766 824 const newcombo & c = combobuf[cmb];
4767 824 int32_t tiletodraw = combo_tile(c, x1, y1);
4768 824 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
4769 824 int32_t skiprows=c.skipanimy;
4770
4771
4772 //don't scale if it's not safe to do so
4773 824 bool canscale = true;
4774
4775
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if(xscale==0||yscale==0)
4776 {
4777 return;
4778 }
4779
4780
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
824 if(xscale<0||yscale<0)
4781 824 canscale = false; //default size
4782
4783
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4784
4785
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4786 {
4787 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
4788
4789 if(transparency)
4790 {
4791 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4792 }
4793 else //no transparency
4794 {
4795 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4796 }
4797
4798 if(rotation != 0) // rotate
4799 {
4800 //fixed point sucks ;0
4801 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
4802 {
4803 int32_t xy[2];
4804 fixed ra1=itofix(sdci[12]%10000)/10000;
4805 fixed ra2=itofix(sdci[12]/10000);
4806 fixed ra=ra1+ra2;
4807 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4808 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4809 x1=xy[0];
4810 y1=xy[1];
4811 }
4812
4813 if(canscale) //scale first
4814 {
4815 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4816 clear_bitmap(tempbit);
4817
4818 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4819
4820 if(opacity < 128)
4821 {
4822 clear_bitmap(prim_bmp);
4823 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4824 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4825 }
4826 else
4827 {
4828 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4829 }
4830
4831 destroy_bitmap(tempbit);
4832 }
4833 else //no scale
4834 {
4835 if(opacity < 128)
4836 {
4837 clear_bitmap(prim_bmp);
4838 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4839 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4840 }
4841 else
4842 {
4843 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4844 }
4845 }
4846 }
4847 else //scale only
4848 {
4849 if(canscale)
4850 {
4851 if(opacity<128)
4852 {
4853 clear_bitmap(prim_bmp);
4854 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4855 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4856 }
4857 else
4858 {
4859 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4860 }
4861 }
4862 else //error -do not scale
4863 {
4864 if(opacity<128)
4865 {
4866 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4867 }
4868 else
4869 {
4870 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4871 }
4872 }
4873 }
4874
4875 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
4876 }
4877 else // no scale or rotation
4878 {
4879
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if(transparency)
4880 {
4881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if(opacity<=127)
4882 TileHelper::OverTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4883 else
4884 824 TileHelper::OverTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4885 824 }
4886 else
4887 {
4888 if(opacity<=127)
4889 TileHelper::PutTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4890 else
4891 TileHelper::OldPutTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4892 }
4893 }
4894 824 }
4895
4896
4897 void bmp_do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4898 {
4899 //sdci[1]=layer
4900 //sdci[2]=x
4901 //sdci[3]=y
4902 //sdci[4]=combo
4903 //sdci[5]=tile width
4904 //sdci[6]=tile height
4905 //sdci[7]=flip
4906 //sdci[17] Bitmap Pointer
4907
4908 int32_t w = sdci[5]/10000;
4909 int32_t h = sdci[6]/10000;
4910
4911 if(w<1||h<1||h>20||w>20)
4912 {
4913 return;
4914 }
4915
4916 if ( sdci[17] <= 0 )
4917 {
4918 Z_scripterrlog("bitmap->DrawComboCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4919 return;
4920 }
4921
4922 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4923 if ( refbmp == NULL ) return;
4924 int32_t cmb = (sdci[4]/10000);
4925 if((unsigned)cmb >= MAXCOMBOS)
4926 {
4927 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4928 return;
4929 }
4930
4931 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4932
4933 int32_t x1=sdci[2]/10000;
4934 int32_t y1=sdci[3]/10000;
4935
4936 const newcombo & c = combobuf[cmb];
4937 int32_t tiletodraw = combo_tile(c, x1, y1);
4938 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
4939 int32_t skiprows=c.skipanimy;
4940
4941 TileHelper::OverTileCloaked(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
4942 }
4943
4944
4945 167316 void bmp_do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4946 {
4947 /* layer, x, y, tile, color opacity */
4948 //sdci[17] Bitmap Pointer
4949
4950 167316 int32_t opacity = sdci[6]/10000;
4951
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 167316 times.
167316 if ( sdci[17] <= 0 )
4952 {
4953 Z_scripterrlog("bitmap->FastTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4954 return;
4955 }
4956 167316 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4957
1/2
✓ Branch 0 taken 167316 times.
✗ Branch 1 not taken.
167316 if ( refbmp == NULL ) return;
4958
4959
2/4
✓ Branch 0 taken 167316 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 167316 times.
✗ Branch 3 not taken.
167316 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4960
4961
2/2
✓ Branch 0 taken 11131 times.
✓ Branch 1 taken 156185 times.
167316 if(opacity < 128)
4962 11131 overtiletranslucent16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
4963 else
4964 156185 overtile16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
4965 167316 }
4966
4967 void do_bmpwritetile(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4968 {
4969 /* layer, x, y, tile, is8bit, mask */
4970 //sdci[17] Bitmap Pointer
4971 if ( sdci[17] <= 0 )
4972 {
4973 Z_scripterrlog("bitmap->WriteTile() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4974 return;
4975 }
4976 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4977 if ( refbmp == NULL ) return;
4978
4979 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4980
4981 int32_t x = (sdci[2]/10000), y = (sdci[3]/10000), tl = (sdci[4]/10000);
4982 bool is8bit = sdci[5]!=0, mask = sdci[6]!=0;
4983
4984 write_tile(newtilebuf, refbmp, tl, x+xoffset, y+yoffset, is8bit, mask);
4985 }
4986
4987 void do_bmpdither(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4988 {
4989 /* layer, mask, color, ditherType, ditherArg */
4990 //sdci[2] Mask Bitmap Pointer
4991 //sdci[3] Color
4992 //sdci[17] Bitmap Pointer
4993 if ( sdci[17] <= 0 )
4994 {
4995 Z_scripterrlog("bitmap->Dither() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4996 return;
4997 }
4998 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
4999 if ( refbmp == NULL ) return;
5000 if ( sdci[2] <= 0 )
5001 {
5002 Z_scripterrlog("bitmap->Dither() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5003 return;
5004 }
5005 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]-10);
5006 if ( mask == NULL ) return;
5007
5008 int32_t dType = sdci[4] / 10000L;
5009 if(dType < 0 || dType >= dithMax)
5010 {
5011 Z_scripterrlog("bitmap->Dither() used an invalid dither type: %d. Aborting.\n", dType);
5012 return;
5013 }
5014
5015 ditherblit(refbmp, mask, byte(sdci[3]/10000L), dType, sdci[5]/10000L);
5016 }
5017
5018 6363 void do_bmpreplcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5019 {
5020 /* layer, shift, startcol, endcol */
5021 //sdci[2] NewCol
5022 //sdci[3] StartCol
5023 //sdci[4] EndCol
5024 //sdci[17] Bitmap Pointer
5025
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6363 times.
6363 if ( sdci[17] <= 0 )
5026 {
5027 Z_scripterrlog("bitmap->ReplaceColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5028 return;
5029 }
5030 6363 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6363 times.
6363 if ( refbmp == NULL ) return;
5032 6363 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, false);
5033 6363 }
5034
5035 void do_bmpshiftcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5036 {
5037 /* layer, shift, startcol, endcol */
5038 //sdci[2] ShiftAmount
5039 //sdci[3] StartCol
5040 //sdci[4] EndCol
5041 //sdci[17] Bitmap Pointer
5042 if ( sdci[17] <= 0 )
5043 {
5044 Z_scripterrlog("bitmap->ShiftColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5045 return;
5046 }
5047 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5048 if ( refbmp == NULL ) return;
5049 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, true);
5050 }
5051
5052 906 void do_bmpmaskdraw(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5053 {
5054 /* layer, mask, color */
5055 //sdci[2] Mask Bitmap Pointer
5056 //sdci[3] Color
5057 //sdci[4] start mask color
5058 //sdci[5] end mask color
5059 //sdci[17] Bitmap Pointer
5060 906 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5061
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( refbmp == NULL )
5062 {
5063 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5064 return;
5065 }
5066 906 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]-10);
5067
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( mask == NULL )
5068 {
5069 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5070 return;
5071 }
5072 906 auto fillcol = sdci[3]/10000L;
5073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(unsigned(fillcol) > 0xFF) return; //invalid color, nothing to draw
5074 906 auto startcol = vbound(sdci[4]/10000L,0x00,0xFF);
5075 906 auto endcol = vbound(sdci[5]/10000L,0x00,0xFF);
5076 906 mask_colorfill(refbmp, mask, fillcol, startcol, endcol);
5077 906 }
5078
5079 void do_bmpmaskblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5080 {
5081 /* layer, mask, color */
5082 //sdci[2] Mask Bitmap Pointer
5083 //sdci[3] Pattern Bitmap
5084 //sdci[4] bool 'pattern repeats'
5085 //sdci[5] start mask color
5086 //sdci[6] end mask color
5087 //sdci[17] Bitmap Pointer
5088 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5089 if ( refbmp == NULL )
5090 {
5091 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5092 return;
5093 }
5094 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]-10);
5095 if ( mask == NULL )
5096 {
5097 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (mask) id: %d. Aborting.\n", sdci[2]);
5098 return;
5099 }
5100 BITMAP *pattern = FFCore.GetScriptBitmap(sdci[3]-10);
5101 if ( pattern == NULL )
5102 {
5103 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (pattern) id: %d. Aborting.\n", sdci[3]);
5104 return;
5105 }
5106 bool repeats = sdci[4]!=0;
5107 auto startcol = vbound(sdci[5]/10000L,0x00,0xFF);
5108 auto endcol = vbound(sdci[6]/10000L,0x00,0xFF);
5109 mask_blit(refbmp, mask, pattern, repeats, startcol, endcol);
5110 }
5111
5112 784 void bmp_do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5113 {
5114 /* layer, x, y, tile, color opacity */
5115 //sdci[17] Bitmap Pointer
5116 784 int32_t opacity = sdci[6] / 10000;
5117 784 int32_t x1 = sdci[2] / 10000;
5118 784 int32_t y1 = sdci[3] / 10000;
5119 784 int32_t index = sdci[4]/10000;
5120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 784 times.
784 if ( sdci[17] <= 0 )
5121 {
5122 Z_scripterrlog("bitmap->FastCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5123 return;
5124 }
5125 784 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5126
1/2
✓ Branch 0 taken 784 times.
✗ Branch 1 not taken.
784 if ( refbmp == NULL ) return;
5127 784 int32_t cmb = (sdci[4]/10000);
5128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 784 times.
784 if((unsigned)cmb >= MAXCOMBOS)
5129 {
5130 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
5131 return;
5132 }
5133
5134
2/4
✓ Branch 0 taken 784 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 784 times.
✗ Branch 3 not taken.
784 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5135
5136 //if( index >= MAXCOMBOS ) return; //bleh.
5137 /*
5138 const newcombo & c = combobuf[index];
5139
5140 if(opacity < 128)
5141 overtiletranslucent16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip, opacity);
5142 else
5143 overtile16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip);
5144 */
5145
5146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 784 times.
784 if(opacity < 128)
5147 {
5148 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
5149 overcomboblocktranslucent(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
5150
5151 }
5152 else
5153 {
5154 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
5155 784 overcomboblock(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
5156 }
5157 784 }
5158
5159
5160
5161 void bmp_do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5162 {
5163 //sdci[17] Bitmap Pointer
5164 if ( sdci[17] <= 0 )
5165 {
5166 Z_scripterrlog("bitmap->DrawCharacter() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5167 return;
5168 }
5169 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5170 if ( refbmp == NULL ) return;
5171
5172 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5173
5174 //broken 2.50.2 and earlier drawcharacter()
5175 if ( get_bit(quest_rules, qr_BROKENCHARINTDRAWING) )
5176 {
5177 //sdci[1]=layer
5178 //sdci[2]=x
5179 //sdci[3]=y
5180 //sdci[4]=font
5181 //sdci[5]=color
5182 //sdci[6]=bg color
5183 //sdci[7]=strech x (width)
5184 //sdci[8]=stretch y (height)
5185 //sdci[9]=char
5186 //sdci[10]=opacity
5187 //sdci[17] Bitmap Pointer
5188
5189 int32_t x=sdci[2]/10000;
5190 int32_t y=sdci[3]/10000;
5191 int32_t font_index=sdci[4]/10000;
5192 int32_t color=sdci[5]/10000;
5193 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5194 int32_t w=sdci[7]/10000;
5195 int32_t h=sdci[8]/10000;
5196 char glyph=char(sdci[9]/10000);
5197 int32_t opacity=sdci[10]/10000;
5198
5199 //safe check
5200 if(bg_color < -1) bg_color = -1;
5201
5202 if(w>512) w=512; //w=vbound(w,0,512);
5203
5204 if(h>512) h=512; //h=vbound(h,0,512);
5205
5206 //undone
5207 if(w>0&&h>0)//stretch the character
5208 {
5209 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5210
5211 if(opacity < 128)
5212 {
5213 if(w>128||h>128)
5214 {
5215 clear_bitmap(prim_bmp);
5216
5217 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5218 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5219 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5220 }
5221 else //this is faster
5222 {
5223 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5224
5225 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5226 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5227 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5228
5229 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5230 }
5231 }
5232 else // no opacity
5233 {
5234 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5235 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5236 }
5237
5238 }
5239 else //no stretch
5240 {
5241 if(opacity < 128)
5242 {
5243 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5244 clear_bitmap(pbmp);
5245
5246 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5247 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5248
5249 destroy_bitmap(pbmp);
5250 }
5251 else // no opacity
5252 {
5253 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5254 }
5255 }
5256 }
5257
5258 else //2.53.0 fixed version and later.
5259 {
5260
5261 //sdci[1]=layer
5262 //sdci[2]=x
5263 //sdci[3]=y
5264 //sdci[4]=font
5265 //sdci[5]=color
5266 //sdci[6]=bg color
5267 //sdci[7]=strech x (width)
5268 //sdci[8]=stretch y (height)
5269 //sdci[9]=char
5270 //sdci[10]=opacity
5271
5272 int32_t x=sdci[2]/10000;
5273 int32_t y=sdci[3]/10000;
5274 int32_t font_index=sdci[4]/10000;
5275 int32_t color=sdci[5]/10000;
5276 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5277 int32_t w=sdci[7]/10000;
5278 int32_t h=sdci[8]/10000;
5279 char glyph=char(sdci[9]/10000);
5280 int32_t opacity=sdci[10]/10000;
5281
5282 //safe check
5283 if(bg_color < -1) bg_color = -1;
5284
5285 if(w>512) w=512; //w=vbound(w,0,512);
5286
5287 if(h>512) h=512; //h=vbound(h,0,512);
5288
5289 //undone
5290 if(w>0&&h>0)//stretch the character
5291 {
5292 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5293
5294 if(opacity < 128)
5295 {
5296 if(w>128||h>128)
5297 {
5298 clear_bitmap(prim_bmp);
5299
5300 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5301 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5302 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5303 }
5304 else //this is faster
5305 {
5306 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5307
5308 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5309 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5310 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5311
5312 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5313 }
5314 }
5315 else // no opacity
5316 {
5317 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5318 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5319 }
5320
5321 }
5322 else //no stretch
5323 {
5324 if(opacity < 128)
5325 {
5326 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5327 clear_bitmap(pbmp);
5328
5329 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5330 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5331
5332 destroy_bitmap(pbmp);
5333 }
5334 else // no opacity
5335 {
5336 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5337 }
5338 }
5339
5340 }
5341
5342 }
5343
5344
5345 void bmp_do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5346 {
5347 if ( sdci[17] <= 0 )
5348 {
5349 Z_scripterrlog("bitmap->DrawInteger() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5350 return;
5351 }
5352 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5353 if ( refbmp == NULL ) return;
5354
5355 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5356
5357 //broken 2.50.2 and earlier drawinteger()
5358 if ( get_bit(quest_rules, qr_BROKENCHARINTDRAWING) )
5359 {
5360 //sdci[1]=layer
5361 //sdci[2]=x
5362 //sdci[3]=y
5363 //sdci[4]=font
5364 //sdci[5]=color
5365 //sdci[6]=bg color
5366 //sdci[7]=strech x (width)
5367 //sdci[8]=stretch y (height)
5368 //sdci[9]=integer
5369 //sdci[10]=num decimal places
5370 //sdci[11]=opacity
5371 //sdci[17] Bitmap Pointer
5372
5373 int32_t x=sdci[2]/10000;
5374 int32_t y=sdci[3]/10000;
5375 int32_t font_index=sdci[4]/10000;
5376 int32_t color=sdci[5]/10000;
5377 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5378 int32_t w=sdci[7]/10000;
5379 int32_t h=sdci[8]/10000;
5380 //float number=static_cast<float>(sdci[9])/10000.0f;
5381 int32_t decplace=sdci[10]/10000;
5382 int32_t opacity=sdci[11]/10000;
5383
5384 //safe check
5385 if(bg_color < -1) bg_color = -1;
5386
5387 if(w>512) w=512; //w=vbound(w,0,512);
5388
5389 if(h>512) h=512; //h=vbound(h,0,512);
5390
5391 char numbuf[15];
5392
5393 switch(decplace)
5394 {
5395 default:
5396 case 0:
5397 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5398 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5399
5400 case 1:
5401 //sprintf(numbuf,"%.01f",number);
5402 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5403 break;
5404
5405 case 2:
5406 //sprintf(numbuf,"%.02f",number);
5407 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5408 break;
5409
5410 case 3:
5411 //sprintf(numbuf,"%.03f",number);
5412 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5413 break;
5414
5415 case 4:
5416 //sprintf(numbuf,"%.04f",number);
5417 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5418 break;
5419 }
5420
5421 if(w>0&&h>0)//stretch
5422 {
5423 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5424
5425 if(opacity < 128)
5426 {
5427 if(w>128||h>128)
5428 {
5429 clear_bitmap(prim_bmp);
5430
5431 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5432 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5433 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5434 }
5435 else
5436 {
5437 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5438 clear_bitmap(pbmp2);
5439
5440 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5441 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5442 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5443
5444 destroy_bitmap(pbmp2);
5445 }
5446 }
5447 else // no opacity
5448 {
5449 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5450 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5451 }
5452
5453 }
5454 else //no stretch
5455 {
5456 if(opacity < 128)
5457 {
5458 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5459 clear_bitmap(pbmp);
5460
5461 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5462 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5463
5464 destroy_bitmap(pbmp);
5465 }
5466 else // no opacity
5467 {
5468 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5469 }
5470 }
5471
5472 }
5473
5474 else //2.53.0 fixed version and later.
5475 {
5476 //sdci[1]=layer
5477 //sdci[2]=x
5478 //sdci[3]=y
5479 //sdci[4]=font
5480 //sdci[5]=color
5481 //sdci[6]=bg color
5482 //sdci[7]=strech x (width)
5483 //sdci[8]=stretch y (height)
5484 //sdci[9]=integer
5485 //sdci[10]=num decimal places
5486 //sdci[11]=opacity
5487
5488 int32_t x=sdci[2]/10000;
5489 int32_t y=sdci[3]/10000;
5490 int32_t font_index=sdci[4]/10000;
5491 int32_t color=sdci[5]/10000;
5492 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5493 int32_t w=sdci[7]/10000;
5494 int32_t h=sdci[8]/10000;
5495 //float number=static_cast<float>(sdci[9])/10000.0f;
5496 //int32_t numberint = sdci[9]/10000;
5497 int32_t decplace=sdci[10]/10000;
5498 int32_t opacity=sdci[11]/10000;
5499
5500 //safe check
5501 if(bg_color < -1) bg_color = -1;
5502
5503 if(w>512) w=512; //w=vbound(w,0,512);
5504
5505 if(h>512) h=512; //h=vbound(h,0,512);
5506
5507 char numbuf[15];
5508
5509 switch(decplace)
5510 {
5511 default:
5512 case 0:
5513 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5514 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5515
5516 case 1:
5517 //sprintf(numbuf,"%.01f",number);
5518 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5519 break;
5520
5521 case 2:
5522 //sprintf(numbuf,"%.02f",number);
5523 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5524 break;
5525
5526 case 3:
5527 //sprintf(numbuf,"%.03f",number);
5528 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5529 break;
5530
5531 case 4:
5532 //sprintf(numbuf,"%.04f",number);
5533 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5534 break;
5535 }
5536
5537 //FONT* font=get_zc_font(sdci[4]/10000);
5538
5539 if(w>0&&h>0)//stretch
5540 {
5541 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
5542 clear_bitmap(pbmp);
5543 //script_drawing_commands.GetSmallTextureBitmap(1,1);
5544
5545 if(opacity < 128)
5546 {
5547 if(w>128||h>128)
5548 {
5549 clear_bitmap(prim_bmp);
5550
5551 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5552 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5553 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5554 }
5555 else
5556 {
5557 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5558 clear_bitmap(pbmp2);
5559
5560 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5561 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5562 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5563
5564 destroy_bitmap(pbmp2);
5565 }
5566 }
5567 else // no opacity
5568 {
5569 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5570 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5571 }
5572
5573 }
5574 else //no stretch
5575 {
5576 if(opacity < 128)
5577 {
5578 FONT* font = get_zc_font(font_index);
5579 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
5580 clear_bitmap(pbmp);
5581
5582 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
5583 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5584
5585 destroy_bitmap(pbmp);
5586 }
5587 else // no opacity
5588 {
5589 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5590 }
5591 }
5592 }
5593 }
5594
5595
5596 void bmp_do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5597 {
5598 //sdci[1]=layer
5599 //sdci[2]=x
5600 //sdci[3]=y
5601 //sdci[4]=font
5602 //sdci[5]=color
5603 //sdci[6]=bg color
5604 //sdci[7]=format_option
5605 //sdci[8]=string
5606 //sdci[9]=opacity
5607 //sdci[17] Bitmap Pointer
5608 if ( sdci[17] <= 0 )
5609 {
5610 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5611 return;
5612 }
5613
5614 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5615 if ( refbmp == NULL ) return;
5616
5617 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5618
5619 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5620
5621 if(!str)
5622 {
5623 al_trace("String pointer is null! Internal error. \n");
5624 return;
5625 }
5626
5627 int32_t x=sdci[2]/10000;
5628 int32_t y=sdci[3]/10000;
5629 FONT* font=get_zc_font(sdci[4]/10000);
5630 int32_t color=sdci[5]/10000;
5631 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5632 int32_t format_type=sdci[7]/10000;
5633 int32_t opacity=sdci[9]/10000;
5634 //sdci[8] not needed :)
5635
5636 //safe check
5637 if(bg_color < -1) bg_color = -1;
5638
5639 if(opacity < 128)
5640 {
5641 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5642 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5643 clear_bitmap(pbmp);
5644 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
5645 if(format_type == 2) // right-sided text
5646 x-=width;
5647 else if(format_type == 1) // centered text
5648 x-=width/2;
5649 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5650 destroy_bitmap(pbmp);
5651 }
5652 else // no opacity
5653 {
5654 if(format_type == 2) // right-sided text
5655 {
5656 textout_right_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5657 }
5658 else if(format_type == 1) // centered text
5659 {
5660 textout_centre_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5661 }
5662 else // standard left-sided text
5663 {
5664 textout_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5665 }
5666 }
5667 }
5668
5669 45504 void bmp_do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5670 {
5671 //sdci[1]=layer
5672 //sdci[2]=x
5673 //sdci[3]=y
5674 //sdci[4]=font
5675 //sdci[5]=color
5676 //sdci[6]=bg color
5677 //sdci[7]=format_option
5678 //sdci[8]=string
5679 //sdci[9]=opacity
5680 //sdci[10]=shadowtype
5681 //sdci[11]=shadow_color
5682 //sdci[17] Bitmap Pointer
5683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if ( sdci[17] <= 0 )
5684 {
5685 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5686 return;
5687 }
5688
5689 45504 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5690
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if ( refbmp == NULL ) return;
5691
5692
2/4
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45504 times.
45504 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5693
5694 45504 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5695
5696
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(!str)
5697 {
5698 al_trace("String pointer is null! Internal error. \n");
5699 return;
5700 }
5701
5702 45504 int32_t x=sdci[2]/10000;
5703 45504 int32_t y=sdci[3]/10000;
5704 45504 FONT* font=get_zc_font(sdci[4]/10000);
5705 45504 int32_t color=sdci[5]/10000;
5706 45504 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5707 45504 int32_t format_type=sdci[7]/10000;
5708 45504 int32_t opacity=sdci[9]/10000;
5709 45504 int32_t textstyle = sdci[10]/10000;
5710 45504 int32_t shadow_color = sdci[11]/10000;
5711 //sdci[8] not needed :)
5712
5713 //safe check
5714
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(bg_color < -1) bg_color = -1;
5715
5716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if(opacity < 128)
5717 {
5718 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5719 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5720 clear_bitmap(pbmp);
5721 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
5722 if(format_type == 2) // right-sided text
5723 x-=width;
5724 else if(format_type == 1) // centered text
5725 x-=width/2;
5726 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5727 destroy_bitmap(pbmp);
5728 }
5729 else // no opacity
5730 {
5731 45504 textout_styled_aligned_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
5732 }
5733 45504 }
5734
5735 26369 void bmp_do_clearr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5736 {
5737 //sdci[1]=layer
5738 //sdci[17] Bitmap Pointer
5739 //Z_scripterrlog("bitmap->Clear() pointer is: %d\n", sdci[17]);
5740
1/2
✓ Branch 0 taken 26369 times.
✗ Branch 1 not taken.
26369 if ( sdci[17] <= 0 )
5741 {
5742 Z_scripterrlog("bitmap->Clear() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5743 return;
5744 }
5745 26369 int32_t bitid = sdci[17] - 10;
5746
1/2
✓ Branch 0 taken 26369 times.
✗ Branch 1 not taken.
26369 if ( scb.script_created_bitmaps[bitid].u_bmp )
5747 26369 clear_bitmap(scb.script_created_bitmaps[bitid].u_bmp);
5748 26369 }
5749
5750 2790 void bmp_do_clearcolorr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5751 {
5752 //sdci[1]=layer
5753 //sdci[2]=color
5754 //sdci[17] Bitmap Pointer
5755 2790 int32_t pal_color = sdci[2]/10000;
5756
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if ( sdci[17] <= 0 )
5757 {
5758 Z_scripterrlog("bitmap->ClearToColor() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5759 return;
5760 }
5761 2790 int32_t bitid = sdci[17] - 10;
5762
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if ( scb.script_created_bitmaps[bitid].u_bmp )
5763 2790 clear_to_color(scb.script_created_bitmaps[bitid].u_bmp, pal_color);
5764 2790 }
5765
5766
5767 34653 void bmp_do_regenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5768 {
5769 //sdci[1]=layer
5770 34653 int32_t h = sdci[3]/10000;
5771 34653 int32_t w = sdci[2]/10000;
5772
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34653 times.
34653 if ( get_bit(quest_rules, qr_OLDCREATEBITMAP_ARGS) )
5773 {
5774 //flip height and width
5775 h = h ^ w;
5776 w = h ^ w;
5777 h = h ^ w;
5778 }
5779 //sdci[17] Bitmap Pointer
5780 //Z_scripterrlog("bitmap->Create() pointer is: %d\n", sdci[17]);
5781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34653 times.
34653 if ( sdci[17] <= 0 )
5782 {
5783 Z_scripterrlog("bitmap->Create() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5784 return;
5785 }
5786 34653 int32_t bitid = sdci[17] - 10;
5787
2/2
✓ Branch 0 taken 34528 times.
✓ Branch 1 taken 125 times.
34653 if ( scb.script_created_bitmaps[bitid].u_bmp )
5788 34528 destroy_bitmap(scb.script_created_bitmaps[bitid].u_bmp);
5789 34653 scb.script_created_bitmaps[bitid].u_bmp = create_bitmap_ex(8,w,h);
5790
5791 34653 scb.script_created_bitmaps[bitid].width = w;
5792 34653 scb.script_created_bitmaps[bitid].height = h;
5793
5794
5795
5796 34653 }
5797
5798 void bmp_do_readr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5799 {
5800 //sdci[1]=layer
5801 //sdci[2]=filename
5802 //sdci[3]=y
5803 //sdci[4]=font
5804 //sdci[5]=color
5805 //sdci[6]=bg color
5806 //sdci[7]=format_option
5807 //sdci[8]=string
5808 //sdci[9]=opacity
5809 //sdci[17] Bitmap Pointer
5810 //Z_scripterrlog("bitmap->Read() pointer is: %d\n", sdci[17]);
5811 if ( sdci[17] <= 0 )
5812 {
5813 Z_scripterrlog("bitmap->Read() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5814 return;
5815 }
5816 int32_t bitid = sdci[17] - 10;
5817 scb.script_created_bitmaps[bitid].destroy();
5818
5819 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5820
5821 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
5822 // std::strncpy(cptr, str->c_str(), str->size());
5823 // Z_scripterrlog("The following should be the filename string:\n");
5824 //Z_scripterrlog(" %s\n", cptr);
5825
5826 if(!str)
5827 {
5828 al_trace("String pointer is null! Internal error. \n");
5829 return;
5830 }
5831
5832 // Z_scripterrlog("Trying to read filename %s\n", cptr);
5833 PALETTE tempPal;
5834 get_palette(tempPal);
5835 if ( checkPath(str->c_str(), false) )
5836 {
5837 scb.script_created_bitmaps[bitid].u_bmp = load_bitmap(str->c_str(), tempPal);
5838 scb.script_created_bitmaps[bitid].width = scb.script_created_bitmaps[bitid].u_bmp->w;
5839 scb.script_created_bitmaps[bitid].height = scb.script_created_bitmaps[bitid].u_bmp->h;
5840 if ( !scb.script_created_bitmaps[bitid].u_bmp )
5841 {
5842 Z_scripterrlog("Failed to load image file %s.\nMaking a blank bitmap on the pointer.\n", str->c_str());
5843 //scb.script_created_bitmaps[bitid].u_bmp = create_bitmap_ex(8,256,176);
5844 //clear_bitmap(scb.script_created_bitmaps[bitid].u_bmp);
5845 }
5846 else
5847 {
5848 zprint("Read image file %s\n",str->c_str());
5849 }
5850 }
5851 else
5852 {
5853 Z_scripterrlog("Failed to load image file: %s. File not found. Creating a blank bitmap on the pointer.\n", str->c_str());
5854 scb.script_created_bitmaps[bitid].u_bmp = create_bitmap_ex(8,256,176);
5855 clear_bitmap(scb.script_created_bitmaps[bitid].u_bmp);
5856 }
5857 }
5858
5859
5860
5861 void bmp_do_writer(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5862 {
5863 //sdci[1]=layer
5864 //sdci[2]=filename
5865 //sdci[3]=y
5866 //sdci[4]=font
5867 //sdci[5]=color
5868 //sdci[6]=bg color
5869 //sdci[7]=format_option
5870 //sdci[8]=string
5871 //sdci[9]=opacity
5872 //sdci[17] Bitmap Pointer
5873 //Z_scripterrlog("bitmap->Write() pointer is: %d\n", sdci[17]);
5874
5875 if ( sdci[17] <= 0 )
5876 {
5877 Z_scripterrlog("bitmap->Write() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5878 return;
5879 }
5880 int32_t bitid = sdci[17] - 10;
5881
5882 if ( !scb.script_created_bitmaps[bitid].u_bmp )
5883 {
5884 Z_scripterrlog("Tried to write from an invalid bitmap pointer %d. Aborting. \n", sdci[17]);
5885 return;
5886 }
5887
5888 bool overwrite = (sdci[3] != 0);
5889 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5890
5891 if(!str)
5892 {
5893 al_trace("String pointer is null! Internal error. \n");
5894 return;
5895 }
5896
5897 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
5898 //std::strncpy(cptr, str->c_str(), str->size());
5899 //Z_scripterrlog("bitmap->Write extension matches ? : %s\n!", (FFCore.checkExtension(str->c_str(), ".png")) ? "true" : "false");
5900 //Z_scripterrlog("Trying to write filename %s\n", cptr);
5901 if
5902 (
5903 ( (FFCore.checkExtension(*str, "")) ) ||
5904 ( !(FFCore.checkExtension(*str, ".png")) && !(FFCore.checkExtension(*str, ".gif")) && !(FFCore.checkExtension(*str, ".bmp"))
5905 && !(FFCore.checkExtension(*str, ".pcx")) && !(FFCore.checkExtension(*str, ".tga")) )
5906 )
5907 {
5908 Z_scripterrlog("No extension, or invalid extension provided for writing bitmap file %s. Could not write the file.\nValid types are .png, .gif, .pcx, .tgx, and .bmp. Aborting.\n",str->c_str());
5909 }
5910 else if ( overwrite || (!checkPath(str->c_str(), false)) )
5911 {
5912 if(create_path(str->c_str()))
5913 {
5914 save_bitmap(str->c_str(), scb.script_created_bitmaps[bitid].u_bmp, RAMpal);
5915 if(checkPath(str->c_str(), false))
5916 {
5917 zprint("Wrote image file %s\n",str->c_str());
5918 }
5919 else
5920 {
5921 Z_scripterrlog("Failed to create file '%s'\n",str->c_str());
5922 }
5923 }
5924 else
5925 {
5926 Z_scripterrlog("Cannot write file '%s' because the directory does not exist, and could not be created.\n", str->c_str());
5927 }
5928 }
5929 else Z_scripterrlog("Cannot write file '%s' because the file already exists in the specified path.\n", str->c_str());
5930 }
5931
5932
5933 void bmp_do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5934 {
5935 //sdci[1]=layer
5936 //sdci[2]=x1
5937 //sdci[3]=y1
5938 //sdci[4]=x2
5939 //sdci[5]=y2
5940 //sdci[6]=x3
5941 //sdci[7]=y3
5942 //sdci[8]=x4
5943 //sdci[9]=y4
5944 //sdci[10]=width
5945 //sdci[11]=height
5946 //sdci[12]=cset
5947 //sdci[13]=flip
5948 //sdci[14]=tile/combo
5949 //sdci[15]=polytype
5950 //sdci[16] = other bitmap as texture
5951 //sdci[17] Bitmap Pointer
5952 Z_scripterrlog("bitmap quad pointer: %d\n", sdci[17]);
5953 if ( sdci[17] <= 0 )
5954 {
5955 Z_scripterrlog("bitmap->Quad() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5956 return;
5957 }
5958 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
5959
5960 if ( !refbmp ) return;
5961
5962 int32_t x1 = sdci[2]/10000;
5963 int32_t y1 = sdci[3]/10000;
5964 int32_t x2 = sdci[4]/10000;
5965 int32_t y2 = sdci[5]/10000;
5966 int32_t x3 = sdci[6]/10000;
5967 int32_t y3 = sdci[7]/10000;
5968 int32_t x4 = sdci[8]/10000;
5969 int32_t y4 = sdci[9]/10000;
5970 int32_t w = sdci[10]/10000;
5971 int32_t h = sdci[11]/10000;
5972 int32_t color = sdci[12]/10000;
5973 int32_t flip=(sdci[13]/10000)&3;
5974 int32_t tile = sdci[14]/10000;
5975 int32_t polytype = sdci[15]/10000;
5976 int32_t quad_render_source = sdci[16]-10;
5977 //Z_scripterrlog("bitmap->Quad() render source is: %d\n", quad_render_source);
5978
5979 bool tex_is_bitmap = ( sdci[16] != 0 );
5980
5981 BITMAP *bmptexture=NULL;
5982 BITMAP *tex=NULL;
5983 polytype = vbound(polytype, 0, 14);
5984
5985 int32_t col[4];
5986 col[0]=col[1]=col[2]=col[3]=color;
5987 bool mustDestroyBmp = false;
5988
5989 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5990
5991 if ( tex_is_bitmap )
5992 {
5993 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
5994 if ( !bmptexture )
5995 {
5996 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
5997 tex_is_bitmap = 0;
5998 }
5999 }
6000
6001 if ( tex_is_bitmap )
6002 {
6003
6004 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6005 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6006 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", w);
6007 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", h);
6008
6009 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6010 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6011 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6012 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6013
6014 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
6015 }
6016 else
6017 {
6018 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6019 if(!tex)
6020 {
6021 //Z_scripterrlog("Bitmap->Quad() found an invalid texture bitmap.\n");
6022 mustDestroyBmp = true;
6023 tex = create_bitmap_ex(8, w*16, h*16);
6024 clear_bitmap(tex);
6025 }
6026
6027 if(tile > 0) // TILE
6028 {
6029 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6030 }
6031
6032 if ( tile < 0 ) // COMBO
6033 {
6034 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
6035 const int32_t tiletodraw = combo_tile(c, x1, y1);
6036 flip = flip ^ c.flip;
6037
6038 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6039 }
6040 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6041 {
6042 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6043 return; //non power of two error
6044 }
6045 //Z_scripterrlog("bitmap->Quad() is trying to blit from a bitmap texture.\n");
6046 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6047 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6048 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6049 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6050
6051 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
6052
6053 }
6054
6055
6056
6057
6058 //todo: finish palette shading
6059 /*
6060 POLYTYPE_FLAT
6061 POLYTYPE_GCOL
6062 POLYTYPE_GRGB
6063 POLYTYPE_ATEX
6064 POLYTYPE_PTEX
6065 POLYTYPE_ATEX_MASK
6066 POLYTYPE_PTEX_MASK
6067 POLYTYPE_ATEX_LIT
6068 POLYTYPE_PTEX_LIT
6069 POLYTYPE_ATEX_MASK_LIT
6070 POLYTYPE_PTEX_MASK_LIT
6071 POLYTYPE_ATEX_TRANS
6072 POLYTYPE_PTEX_TRANS
6073 POLYTYPE_ATEX_MASK_TRANS
6074 POLYTYPE_PTEX_MASK_TRANS
6075 */
6076
6077 if(mustDestroyBmp)
6078 destroy_bitmap(tex);
6079
6080 }
6081
6082
6083 void bmp_do_getpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6084 {
6085 //sdci[1]=layer
6086 //sdci[2]=x1
6087 //sdci[3]=y1
6088
6089 //sdci[17] Bitmap Pointer
6090 if ( sdci[17] <= 0 )
6091 {
6092 Z_scripterrlog("bitmap->GetPixel() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[17]);
6093 return;
6094 }
6095 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
6096 if ( refbmp == NULL ) return;
6097
6098
6099 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6100
6101 int32_t x1 = sdci[2]/10000;
6102 int32_t y1 = (sdci[3]/10000)+yoffset;
6103 int32_t col = getpixel(scb.script_created_bitmaps[(sdci[17]-10)].u_bmp, x1, y1);
6104 Z_scripterrlog("bitmap->GetPixel col is %d\n",col);
6105 Z_scripterrlog("bitmap->GetPixel bitmap ptr is is %d\n",(sdci[17]-10));
6106 FFCore.set_sarg1(col);
6107 }
6108
6109
6110
6111
6112 void bmp_do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6113 {
6114 //sdci[1]=layer
6115 //sdci[2]=x1
6116 //sdci[3]=y1
6117 //sdci[4]=x2
6118 //sdci[5]=y2
6119 //sdci[6]=x3
6120 //sdci[7]=y3
6121 //sdci[8]=width
6122 //sdci[9]=height
6123 //sdci[10]=cset
6124 //sdci[11]=flip
6125 //sdci[12]=tile/combo
6126 //sdci[13]=polytype
6127 //sdci[17] Bitmap Pointer
6128 if ( sdci[17] <= 0 )
6129 {
6130 Z_scripterrlog("bitmap->Triangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
6131 return;
6132 }
6133 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
6134 if ( refbmp == NULL ) return;
6135
6136
6137 int32_t render_source = sdci[14]-10;
6138 //Z_scripterrlog("bitmap->Triangle() render source is: %d\n", render_source);
6139
6140 bool tex_is_bitmap = ( sdci[14] != 0 );
6141
6142 BITMAP *bmptexture=NULL;
6143 if ( tex_is_bitmap )
6144 {
6145 bmptexture = FFCore.GetScriptBitmap(render_source);
6146 if ( !bmptexture )
6147 {
6148 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6149 tex_is_bitmap = 0;
6150 }
6151 }
6152
6153 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6154
6155 int32_t x1 = sdci[2]/10000;
6156 int32_t y1 = sdci[3]/10000;
6157 int32_t x2 = sdci[4]/10000;
6158 int32_t y2 = sdci[5]/10000;
6159 int32_t x3 = sdci[6]/10000;
6160 int32_t y3 = sdci[7]/10000;
6161 int32_t w = sdci[8]/10000;
6162 int32_t h = sdci[9]/10000;
6163 int32_t color = sdci[10]/10000;
6164 int32_t flip=(sdci[11]/10000)&3;
6165 int32_t tile = sdci[12]/10000;
6166 int32_t polytype = sdci[13]/10000;
6167
6168 polytype = vbound(polytype, 0, 14);
6169 int32_t utex_w = w;
6170 int32_t utex_h = h;
6171
6172
6173 int32_t tex_width = w*16;
6174 int32_t tex_height = h*16;
6175
6176 bool mustDestroyBmp = false;
6177 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6178
6179 if(!tex)
6180 {
6181 mustDestroyBmp = true;
6182 tex = create_bitmap_ex(8, tex_width, tex_height);
6183 clear_bitmap(tex);
6184 }
6185
6186 int32_t col[3];
6187 /*
6188 if( color < 0 )
6189 {
6190 col[0]=draw_container.color_buffer[0];
6191 col[1]=draw_container.color_buffer[1];
6192 col[2]=draw_container.color_buffer[2];
6193 }
6194 else */
6195 {
6196 col[0]=col[1]=col[2]=color;
6197 }
6198
6199 if(tile > 0) // TILE
6200 {
6201 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6202 }
6203 else // COMBO
6204 {
6205 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
6206 const int32_t tiletodraw = combo_tile(c, x1, y1);
6207 flip = flip ^ c.flip;
6208
6209 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6210 }
6211 if ( !tex_is_bitmap )
6212 {
6213 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6214 {
6215 Z_message("bitmap->Triangle() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6216 return; //non power of two error
6217 }
6218 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6219 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
6220 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
6221
6222
6223 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
6224
6225 }
6226
6227 else
6228 {
6229 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6230 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6231 if ( !isPowerOfTwo(utex_h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_w);
6232 if ( !isPowerOfTwo(utex_w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_h);
6233
6234 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6235 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(utex_h), col[1] };
6236 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(utex_w), static_cast<float>(utex_h), col[2] };
6237
6238
6239 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
6240
6241 }
6242
6243 if(mustDestroyBmp)
6244 destroy_bitmap(tex);
6245 }
6246
6247
6248 void bmp_do_mode7r(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6249 {
6250 /*
6251 int32_t layer, int32_t rt, int32_t srcX, int32_t srcY, int32_t srcW, int32_t srcH, int32_t destW, int32_t destH, int32_t angle, int32_t cx, int32_t cy, int32_t space_z, int32_t horizon,
6252 int32_t scale_x, int32_t scale_y){
6253
6254 //sdci[1]=layer
6255 //sdci[2]=bitmap target
6256 //
6257 // -2 is the current Render Target
6258 // -1, this is the screen (framebuf).
6259 // 0: Render target 0
6260 // 1: Render target 1
6261 // 2: Render target 2
6262 // 3: Render target 3
6263 // 4: Render target 4
6264 // 5: Render target 5
6265 // 6: Render target 6
6266 // Otherwise: The pointer to a bitmap.
6267
6268 //sdci[3]=sourcex
6269 //sdci[4]=sourcey
6270 //sdci[5]=sourcew
6271 //sdci[6]=sourceh
6272
6273 //sdci[7]=destw
6274 //sdci[8]=desth
6275 //sdci[9]=angle
6276 //scdi[10] = pivot cx
6277 //sdci[11] = pivot cy
6278 //sdci[12] = space Z
6279 //sdci[13] = horizon
6280 //scdi[14] = scale X
6281 //scdi[15] = scale Y
6282 //sdci[16] = masked?
6283 //sdci[17] Bitmap Pointer
6284
6285
6286
6287 // ZScript-side constant values:
6288 const int32_t BITDX_NORMAL = 0;
6289 const int32_t BITDX_TRANS = 1; //Translucent
6290 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6291 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6292 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6293 //Note: Some modes cannot be combined. if a combination is not supported, an error
6294 // detailing this will be shown in allegro.log.
6295
6296 //scdi[15] = litcolour
6297 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6298 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6299
6300 //sdci[16]=mask
6301
6302 */
6303
6304
6305 int32_t bitmapIndex = sdci[2];
6306 int32_t usr_bitmap_index = sdci[2]-10;
6307 byte using_user_bitmap = 0;
6308 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6309 //Z_scripterrlog("DrawPlane() bitmapIndex is: %d\n", bitmapIndex);
6310
6311 if ( bitmapIndex >= 10000 )
6312 {
6313 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6314 }
6315 else if ( usr_bitmap_index > 0 )
6316 {
6317 bitmapIndex = usr_bitmap_index;
6318 using_user_bitmap = 1;
6319 // Z_scripterrlog("Mode7 is using a user bitmap target, pointer: %d\n", usr_bitmap_index);
6320 yoffset = 0;
6321 }
6322
6323 //int32_t sx = sdci[3]/10000;
6324 //int32_t sy = sdci[4]/10000;
6325 //int32_t sw = sdci[5]/10000;
6326 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
6327 //int32_t sh = sdci[6]/10000;
6328 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
6329 //int32_t dx = sdci[7]/10000;
6330 //int32_t dy = sdci[8]/10000;
6331 //int32_t dw = sdci[9]/10000;
6332 //int32_t dh = sdci[10]/10000;
6333 //float rot = sdci[11]/10000;
6334 //int32_t cx = sdci[12]/10000;
6335 //int32_t cy = sdci[13]/10000;
6336 //int32_t mode = sdci[14]/10000;
6337 //int32_t litcolour = sdci[15]/10000;
6338
6339 //rendering mode 7 args
6340 double srcX = sdci[3]/10000.0;
6341 double srcY = sdci[4]/10000.0;
6342 double destX = sdci[5]/10000.0;
6343 double destY = sdci[6]/10000.0;
6344
6345
6346 // int32_t srcW = sdci[5]/10000;
6347 // int32_t srcH = sdci[6]/10000;
6348 double destW = sdci[7]/10000.0;
6349 double destH = sdci[8]/10000.0;
6350 // int32_t angle = sdci[9]/10000;
6351 // int32_t cx = sdci[10]/10000;
6352 // int32_t cy = sdci[11]/10000;
6353 double space_z = sdci[9]/10000.0;
6354 double horizon = sdci[10]/10000.0;
6355 double scale_x = sdci[11]/10000.0;
6356 double scale_y = sdci[12]/10000.0;
6357 byte masked = ( sdci[13] ) ? 1 : 0;
6358
6359
6360 int32_t ref = 0;
6361
6362 //dx = 0 + xoffset;
6363 //dy = 0 + yoffset;
6364
6365 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6366 //Do we need to also check the render target and do the same thing if the
6367 //dest == -2 and the render target is not RT_SCREEN?
6368
6369 ref = sdci[17];
6370 //Z_scripterrlog("bitmap->DrawPlane() ref id this frame is: %d\n", ref);
6371 ref -=10;
6372 //Z_scripterrlog("bitmap->DrawPlane() modified ref id this frame is: %d\n", ref);
6373
6374
6375 if ( ref <= 0 )
6376 {
6377 Z_scripterrlog("bitmap->DrawPlane() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6378 return;
6379 }
6380 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6381
6382 if(!sourceBitmap)
6383 {
6384 Z_message("Warning: %d->DrawPlane() source bitmap contains invalid data or is not initialized.\n", ref);
6385 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6386 return;
6387 }
6388
6389 BITMAP *destBMP=NULL;
6390 //zprint2("mode 7 bitmap index is: %d\n",bitmapIndex);
6391 switch(bitmapIndex)
6392 {
6393 case -2:
6394 {
6395 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6396 //zprint2("current RT is: %d\n", curr_rt);
6397 if ( curr_rt >= 0 && curr_rt < 7 )
6398 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6399 else destBMP = bmp; //screen
6400 break;
6401 }
6402 case -1:
6403 destBMP = bmp; //this is framebuf, by default
6404 break;
6405 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6406 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6407 //destBMP = framebuf; //Drawing to the screen.
6408 //break;
6409
6410 //1 through 6 are the old system bitmaps (Render Targets)
6411 case 0:
6412 case 1:
6413 case 2:
6414 case 3:
6415 case 4:
6416 case 5:
6417 case 6:
6418 {
6419 //This gets a render target.
6420 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6421
6422 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6423 //sdci[18] = bitmapIndex;
6424 break;
6425 }
6426 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6427 default:
6428 {
6429 destBMP = scb.script_created_bitmaps[usr_bitmap_index].u_bmp;
6430 //sdci[18] = usr_bitmap_index;
6431 if ( !scb.script_created_bitmaps[usr_bitmap_index].u_bmp )
6432 {
6433 Z_scripterrlog("Target for bitmap->DrawPlane is uninitialised. Aborting.\n");
6434 break;
6435 }
6436 }
6437 //FFCore.get_user_bitmap(bitmapIndex); break;
6438 }
6439
6440 if (!destBMP)
6441 {
6442 Z_message("Warning: DrawPlane(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6443 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6444 return;
6445 }
6446
6447 //dx = dx + xoffset; //don't do this here!
6448 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6449 //All of these are a factor of 10000 as fix.
6450 int32_t screen_x = 0; int32_t screen_y = 0;
6451
6452 double distance = 0; double horizontal_scale = 0;
6453
6454 int32_t screen_y_horizon = 0;
6455
6456 double line_dx = 0; double line_dy = 0;
6457
6458 int32_t space_x = 0; int32_t space_y = 0;
6459
6460 for(screen_y = 0; screen_y < destH; screen_y++) //fix, offset by .0000
6461 {
6462 //Calculate the distance of each line from the camera point
6463 screen_y_horizon = screen_y + horizon;
6464
6465 distance = ((space_z * scale_y) / ((screen_y_horizon != 0) ? screen_y_horizon : 1));
6466
6467 //Get the scale of each line based on the distance
6468
6469 horizontal_scale = (distance / (( scale_x != 0 ) ? scale_x : 1));
6470
6471 //There was some math here before I stripped out the rotation step
6472 line_dx = horizontal_scale;
6473 line_dy = 0;
6474
6475 //space_x,space_y - where to grab each scanline from on the space bitmap
6476 space_x = srcX - destW/2.0 * line_dx;
6477 space_y = srcY - distance + destH/2.0 * line_dy;
6478
6479 //Keep blits within the bounds of both bitmaps to avoid crashes
6480 int32_t y1 = srcY+space_y;
6481 int32_t y2 = destY+screen_y;
6482 if(y1 >=0 && y1 <= (sourceBitmap->h-1) && y2 >=0 && y2 <= (destBMP->h-1) )
6483 {
6484 if ( masked ) masked_stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6485 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6486 else stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6487 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6488 }
6489 }
6490 }
6491
6492
6493 //Draw]()
6494 236166 void bmp_do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6495 {
6496 /*
6497 //sdci[1]=layer
6498 //sdci[2]=bitmap target
6499 //
6500 // -2 is the current Render Target
6501 // -1, this is the screen (framebuf).
6502 // 0: Render target 0
6503 // 1: Render target 1
6504 // 2: Render target 2
6505 // 3: Render target 3
6506 // 4: Render target 4
6507 // 5: Render target 5
6508 // 6: Render target 6
6509 // Otherwise: The pointer to a bitmap.
6510
6511 //sdci[3]=sourcex
6512 //sdci[4]=sourcey
6513 //sdci[5]=sourcew
6514 //sdci[6]=sourceh
6515 //sdci[7]=destx
6516 //sdci[8]=desty
6517 //sdci[9]=destw
6518 //sdci[10]=desth
6519 //sdci[11]=rotation/angle
6520 //scdi[12] = pivot cx
6521 //sdci[13] = pivot cy
6522 //scdi[14] = effect flags
6523 //sdci[17] Bitmap Pointer
6524
6525 // ZScript-side constant values:
6526 const int32_t BITDX_NORMAL = 0;
6527 const int32_t BITDX_TRANS = 1; //Translucent
6528 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6529 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6530 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6531 //Note: Some modes cannot be combined. if a combination is not supported, an error
6532 // detailing this will be shown in allegro.log.
6533
6534 //scdi[15] = litcolour
6535 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6536 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6537
6538 //sdci[16]=mask
6539
6540 */
6541
6542 236166 int32_t bitmapIndex = sdci[2]/10000;
6543 236166 int32_t usr_bitmap_index = sdci[2]-10;
6544 236166 byte using_user_bitmap = 0;
6545 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6546 //Z_scripterrlog("Blit() bitmapIndex is: %d\n", bitmapIndex);
6547 #if LOG_BMPBLIT_LEVEL > 0
6548 Z_scripterrlog("Blit() found a dest bitmap ID of: %d\n",bitmapIndex);
6549 #endif
6550
1/2
✓ Branch 0 taken 236166 times.
✗ Branch 1 not taken.
236166 if ( bitmapIndex > 10000 )
6551 {
6552 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6553 }
6554
3/4
✓ Branch 0 taken 172223 times.
✓ Branch 1 taken 63943 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 172223 times.
236166 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
6555 {
6556 172223 bitmapIndex = usr_bitmap_index;
6557 172223 using_user_bitmap = 1;
6558 172223 yoffset = 0;
6559 172223 }
6560
6561 236166 int32_t sx = sdci[3]/10000;
6562 236166 int32_t sy = sdci[4]/10000;
6563 236166 int32_t sw = sdci[5]/10000;
6564 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
6565 236166 int32_t sh = sdci[6]/10000;
6566 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
6567 236166 int32_t dx = sdci[7]/10000;
6568 236166 int32_t dy = sdci[8]/10000;
6569 236166 int32_t dw = sdci[9]/10000;
6570 236166 int32_t dh = sdci[10]/10000;
6571 236166 float rot = sdci[11]/10000;
6572 236166 int32_t cx = sdci[12]/10000;
6573 236166 int32_t cy = sdci[13]/10000;
6574 236166 int32_t mode = sdci[14]/10000;
6575 236166 int32_t litcolour = sdci[15]/10000;
6576 236166 bool masked = (sdci[16] != 0);
6577
6578 236166 int32_t ref = 0;
6579
6580 236166 dx = dx + xoffset;
6581 236166 dy = dy + yoffset;
6582
6583
2/4
✓ Branch 0 taken 236166 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 236166 times.
236166 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6584 //Do we need to also check the render target and do the same thing if the
6585 //dest == -2 and the render target is not RT_SCREEN?
6586
6587 236166 ref = sdci[17];
6588 //Z_scripterrlog("bitmap->blit() ref id this frame is: %d\n", ref);
6589 236166 ref -=10;
6590 //Z_scripterrlog("bitmap->blit() modified ref id this frame is: %d\n", ref);
6591
6592
6593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 236166 times.
236166 if ( ref <= 0 )
6594 {
6595 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6596 return;
6597 }
6598 236166 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6599 #if LOG_BMPBLIT_LEVEL > 0
6600 Z_scripterrlog("bitmap->Blit() is trying to blit to ref: %d\n",sdci[17]);
6601 #endif
6602
1/2
✓ Branch 0 taken 236166 times.
✗ Branch 1 not taken.
236166 if(!sourceBitmap)
6603 {
6604
6605 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
6606 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6607 return;
6608 }
6609
6610 236166 BITMAP *destBMP=NULL;
6611 //zprint2("blit () bitmap index is: %d\n",bitmapIndex);
6612
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 172223 times.
✓ Branch 2 taken 786 times.
✓ Branch 3 taken 63157 times.
236166 switch(bitmapIndex)
6613 {
6614 case -2:
6615 {
6616 786 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6617 //zprint2("current RT is: %d\n", curr_rt);
6618
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
786 if ( curr_rt >= 0 && curr_rt < 7 )
6619 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6620 786 else destBMP = bmp; //screen
6621 786 break;
6622 }
6623 case -1:
6624 63157 destBMP = bmp; //this is framebuf, by default
6625 63157 break;
6626 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6627 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6628 //destBMP = framebuf; //Drawing to the screen.
6629 //break;
6630
6631 //1 through 6 are the old system bitmaps (Render Targets)
6632 case 0:
6633 case 1:
6634 case 2:
6635 case 3:
6636 case 4:
6637 case 5:
6638 case 6:
6639 {
6640 //This gets a render target.
6641 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6642
6643 //destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6644 //sdci[18] = bitmapIndex;
6645 break;
6646 }
6647 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6648 default:
6649 {
6650 172223 destBMP = scb.script_created_bitmaps[usr_bitmap_index].u_bmp;
6651 //sdci[18] = usr_bitmap_index;
6652
1/2
✓ Branch 0 taken 172223 times.
✗ Branch 1 not taken.
172223 if ( !scb.script_created_bitmaps[usr_bitmap_index].u_bmp )
6653 {
6654 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
6655 break;
6656 }
6657 }
6658 //FFCore.get_user_bitmap(bitmapIndex); break;
6659 172223 }
6660
6661
6662
6663 #if LOG_BMPBLIT_LEVEL > 0
6664 Z_scripterrlog("bitmap->Blit() is trying to blit to dest bitmap ID: %d\n",bitmapIndex);
6665 #endif
6666
6667
6668
1/2
✓ Branch 0 taken 236166 times.
✗ Branch 1 not taken.
236166 if (!destBMP)
6669 {
6670
6671 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6672 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6673 return;
6674 }
6675
6676 //bugfix
6677 //sx = vbound(sx, 0, sourceBitmap->w);
6678 #if LOG_BMPBLIT_LEVEL > 0
6679 Z_scripterrlog("Blit %s is: %d\n", "sx", sx);
6680 Z_scripterrlog("Blit %s is: %d\n", "source->w", sourceBitmap->w);
6681 #endif
6682 //sy = vbound(sy, 0, sourceBitmap->h);
6683 #if LOG_BMPBLIT_LEVEL > 0
6684 Z_scripterrlog("Blit %s is: %d\n", "sy", sy);
6685 Z_scripterrlog("Blit %s is: %d\n", "source->h", sourceBitmap->h);
6686 #endif
6687 //sw = vbound(sw, 0, sourceBitmap->w - sx); //keep the w/h within range as well
6688 #if LOG_BMPBLIT_LEVEL > 0
6689 Z_scripterrlog("Blit %s is: %d\n", "sw", sw);
6690 #endif
6691 //sh = vbound(sh, 0, sourceBitmap->h - sy);
6692 #if LOG_BMPBLIT_LEVEL > 0
6693 Z_scripterrlog("Blit %s is: %d\n", "sh", sh);
6694
6695 Z_scripterrlog("Blit %s is: %d\n", "dh", dh);
6696 Z_scripterrlog("Blit %s is: %d\n", "dw", dw);
6697 #endif
6698
2/2
✓ Branch 0 taken 1027 times.
✓ Branch 1 taken 235139 times.
236166 bool stretched = (sw != dw || sh != dh);
6699 //bool stretched = (sourceBitmap->w != destBMP->w || sourceBitmap->h != destBMP->h);
6700 #if LOG_BMPBLIT_LEVEL > 0
6701 Z_scripterrlog("Blit %s is: %s\n", "stretched", stretched ? "true" : "false");
6702 #endif
6703 //BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6704
6705
6706
6707
6708
6709 236166 BITMAP* subBmp = 0;
6710
6711 /* IDR what this was. -Z ( 17th April, 2019 )
6712 if ( bitmapIndex == -1 ) {
6713 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
6714 }
6715 */
6716
6717
4/4
✓ Branch 0 taken 234587 times.
✓ Branch 1 taken 1579 times.
✓ Branch 2 taken 24951 times.
✓ Branch 3 taken 209636 times.
236166 if(rot != 0 || mode != 0)
6718 {
6719 26530 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
6720 26530 clear_bitmap(subBmp);
6721
6722
1/2
✓ Branch 0 taken 26530 times.
✗ Branch 1 not taken.
26530 if(!subBmp)
6723 {
6724
6725 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
6726 return;
6727 }
6728 26530 }
6729 236166 BITMAP* sbmp = sourceBitmap;
6730
2/4
✓ Branch 0 taken 236166 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 236166 times.
236166 if (sx + sw > sbmp->w || sy + sh > sbmp->h)
6731 {
6732 sbmp = create_bitmap_ex(8, sw, sh);
6733 clear_bitmap(sbmp);
6734 blit(sourceBitmap, sbmp, sx, sy, 0, 0, std::min(sourceBitmap->w-sx, sw), std::min(sourceBitmap->h-sy, sh));
6735 sx = 0;
6736 sy = 0;
6737 }
6738 //dx = dx + xoffset; //don't do this here!
6739 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6740
6741
2/2
✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 234564 times.
236166 if(stretched)
6742 {
6743
2/2
✓ Branch 0 taken 1475 times.
✓ Branch 1 taken 127 times.
1602 if(masked)
6744 { //stretched and masked
6745
2/2
✓ Branch 0 taken 574 times.
✓ Branch 1 taken 901 times.
1475 if ( rot == 0 )
6746 { //if not rotated
6747
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
901 switch(mode)
6748 {
6749 case 1:
6750 //transparent
6751 900 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6752 900 draw_trans_sprite(destBMP, subBmp, dx, dy);
6753 900 break;
6754
6755
6756 case 2:
6757 //pivot?
6758 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6759 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6760 //Pivoting requires two more args
6761 break;
6762
6763 case 3:
6764 //pivot + trans
6765 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6766 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6767 break;
6768
6769 case 4:
6770 //flip v
6771 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6772 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6773 break;
6774
6775 case 5:
6776 //trans + v flip
6777 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6778 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6779 break;
6780
6781 case 6:
6782 //pivot + v flip
6783 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6784 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6785 break;
6786
6787 case 8:
6788 //vlip h
6789 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6790 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6791 break;
6792
6793 case 9:
6794 //trans + h flip
6795 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6796 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6797 break;
6798
6799 case 10:
6800 //flip H and pivot
6801 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6802 //return error cannot pivot and h flip
6803 break;
6804
6805 case 12:
6806 //vh flip
6807 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6808 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6809 break;
6810
6811 case 13:
6812 //trans + vh flip
6813 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6814 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6815 break;
6816
6817 case 14:
6818 //pivot and vh flip
6819 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6820 //return error cannot both pivot and vh flip
6821 break;
6822
6823 case 16:
6824 //lit
6825 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6826 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6827 break;
6828
6829 case 18:
6830 //pivot, lit
6831 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6832 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6833 break;
6834
6835 case 20:
6836 //lit + v flip
6837 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6838 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6839 break;
6840
6841 case 22:
6842 //Pivot, vflip, lit
6843 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6844 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6845 break;
6846
6847 case 24:
6848 //lit + h flip
6849 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6850 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6851 break;
6852
6853 case 26:
6854 //pivot + lit + hflip
6855 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
6856 //return error cannot pivot, lit, and flip
6857 break;
6858
6859 case 28:
6860 //lit + vh flip
6861 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6862 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
6863 break;
6864
6865 case 32: //gouraud
6866 //Probably not wort supporting.
6867 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6868 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6869 break;
6870
6871 case 0:
6872 //no effect
6873 1 masked_stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
6874 1 break;
6875
6876
6877 default:
6878
6879 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6880
6881
6882 }
6883 901 } //end if not rotated
6884
6885
2/2
✓ Branch 0 taken 901 times.
✓ Branch 1 taken 574 times.
1475 if ( rot != 0 ) //if rotated
6886 {
6887
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 574 times.
✗ Branch 21 not taken.
574 switch(mode)
6888 {
6889 case 1:
6890 //transparent
6891 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6892 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6893
6894 break;
6895
6896 case 2:
6897 //pivot?
6898 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6899 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6900 //Pivoting requires two more args
6901 break;
6902
6903 case 3:
6904 //pivot + trans
6905 //return an error, cannot both rotate and pivot
6906 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6907 break;
6908
6909 case 4:
6910 //flip v
6911 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6912 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6913 break;
6914
6915 case 5:
6916 //trans + v flip
6917 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6918 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6919 break;
6920
6921 case 6:
6922 //pivot + v flip
6923 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6924 //return an error, cannot both rotate and pivot
6925 break;
6926
6927 case 8:
6928 //flip h
6929 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
6930 //return an error, cannot both rotate and flip H
6931 break;
6932
6933 case 9:
6934 //trans + h flip
6935 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
6936 //return an error, cannot rotate and flip a trans sprite
6937 break;
6938
6939 case 10:
6940 //flip H and pivot
6941 //return error cannot pivot and h flip
6942 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6943 break;
6944
6945 case 12:
6946 //vh flip
6947 //return an error, cannot rotate and VH flip a trans sprite
6948 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6949 break;
6950
6951 case 13:
6952 //trans + vh flip
6953 //return an error, cannot rotate and VH flip a trans sprite
6954 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6955 break;
6956
6957 case 14:
6958 //pivot and vh flip
6959 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6960 //return error cannot both pivot and vh flip
6961 break;
6962
6963 case 16:
6964 //lit
6965 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6966 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6967 break;
6968
6969 case 18:
6970 //pivot, lit
6971 //return an error, cannot both rotate and pivot
6972 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6973 break;
6974
6975 case 20:
6976 //lit + vflip
6977 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6978 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6979 break;
6980
6981 case 22:
6982 //Pivot, vflip, lit
6983 //return an error, cannot both rotate and pivot
6984 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6985 break;
6986
6987 case 24:
6988 //lit + h flip
6989 //return an error, cannot both rotate and H flip
6990 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
6991 break;
6992
6993 case 26:
6994 //pivot + lit + hflip
6995 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
6996 //return error cannot pivot, lit, and flip
6997 break;
6998
6999 case 28:
7000 //lit + vh flip
7001 //return an error, cannot both rotate and VH flip
7002 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7003 break;
7004
7005 case 32: //gouraud
7006 //Probably not wort supporting.
7007 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7008 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7009 break;
7010
7011 case 0:
7012 //no effect.
7013 574 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7014 574 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7015 574 break;
7016
7017 default:
7018
7019 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7020
7021 }
7022 574 }
7023 1475 } //end if stretched and masked
7024
7025 else //stretched, not masked
7026 {
7027
7028
7029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( rot == 0 ) //if not rotated
7030 {
7031
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 127 times.
127 switch(mode)
7032 {
7033 case 1:
7034 //transparent
7035 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7036 draw_trans_sprite(destBMP, subBmp, dx, dy);
7037 break;
7038
7039
7040 case 2:
7041 //pivot?
7042 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7043 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7044 //Pivoting requires two more args
7045 break;
7046
7047 case 3:
7048 //pivot + trans
7049 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7050 pivot_sprite_trans(destBMP, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
7051 break;
7052
7053 case 4:
7054 //flip v
7055 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7056 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7057 break;
7058
7059 case 5:
7060 //trans + v flip
7061 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7062 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7063 break;
7064
7065 case 6:
7066 //pivot + v flip
7067 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7068 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7069 break;
7070
7071 case 8:
7072 //vlip h
7073 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7074 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7075 break;
7076
7077 case 9:
7078 //trans + h flip
7079 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7080 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7081 break;
7082
7083 case 10:
7084 //flip H and pivot
7085 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7086 //return error cannot pivot and h flip
7087 break;
7088
7089 case 12:
7090 //vh flip
7091 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7092 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7093 break;
7094
7095 case 13:
7096 //trans + vh flip
7097 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7098 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7099 break;
7100
7101 case 14:
7102 //pivot and vh flip
7103 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7104 //return error cannot both pivot and vh flip
7105 break;
7106
7107 case 16:
7108 //lit
7109 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7110 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7111 break;
7112
7113 case 18:
7114 //pivot, lit
7115 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7116 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7117 break;
7118
7119 case 20:
7120 //lit + v flip
7121 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7122 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7123 break;
7124
7125 case 22:
7126 //Pivot, vflip, lit
7127 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7128 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7129 break;
7130
7131 case 24:
7132 //lit + h flip
7133 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7134 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7135 break;
7136
7137 case 26:
7138 //pivot + lit + hflip
7139 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7140 //return error cannot pivot, lit, and flip
7141 break;
7142
7143 case 28:
7144 //lit + vh flip
7145 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7146 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7147 break;
7148
7149 case 32: //gouraud
7150 //Probably not wort supporting.
7151 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7152 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7153 break;
7154
7155 case 0:
7156 //no effect
7157 127 stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
7158 127 break;
7159
7160
7161 default:
7162
7163 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7164
7165
7166 }
7167 127 } //end if not rotated
7168
7169
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if ( rot != 0 ) //if rotated
7170 {
7171 switch(mode)
7172 {
7173 case 1:
7174 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7175 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7176
7177 break;
7178
7179 case 2:
7180 //pivot?
7181 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7182 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7183 //Pivoting requires two more args
7184 break;
7185
7186 case 3:
7187 //pivot + trans
7188 //return an error, cannot both rotate and pivot
7189 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7190 break;
7191
7192 case 4:
7193 //flip v
7194 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7195 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7196 break;
7197
7198 case 5:
7199 //trans + v flip
7200 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7201 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7202 break;
7203
7204 case 6:
7205 //pivot + v flip
7206 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7207 //return an error, cannot both rotate and pivot
7208 break;
7209
7210 case 8:
7211 //flip h
7212 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7213 //return an error, cannot both rotate and flip H
7214 break;
7215
7216 case 9:
7217 //trans + h flip
7218 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7219 //return an error, cannot rotate and flip a trans sprite
7220 break;
7221
7222 case 10:
7223 //flip H and pivot
7224 //return error cannot pivot and h flip
7225 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7226 break;
7227
7228 case 12:
7229 //vh flip
7230 //return an error, cannot rotate and VH flip a trans sprite
7231 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7232 break;
7233
7234 case 13:
7235 //trans + vh flip
7236 //return an error, cannot rotate and VH flip a trans sprite
7237 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7238 break;
7239
7240 case 14:
7241 //pivot and vh flip
7242 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7243 //return error cannot both pivot and vh flip
7244 break;
7245
7246 case 16:
7247 //lit
7248 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7249 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7250 break;
7251
7252 case 18:
7253 //pivot, lit
7254 //return an error, cannot both rotate and pivot
7255 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7256 break;
7257
7258 case 20:
7259 //lit + vflip
7260 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7261 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7262 break;
7263
7264 case 22:
7265 //Pivot, vflip, lit
7266 //return an error, cannot both rotate and pivot
7267 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7268 break;
7269
7270 case 24:
7271 //lit + h flip
7272 //return an error, cannot both rotate and H flip
7273 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7274 break;
7275
7276 case 26:
7277 //pivot + lit + hflip
7278 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7279 //return error cannot pivot, lit, and flip
7280 break;
7281
7282 case 28:
7283 //lit + vh flip
7284 //return an error, cannot both rotate and VH flip
7285 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7286 break;
7287
7288 case 32: //gouraud
7289 //Probably not wort supporting.
7290 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7291 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7292 break;
7293
7294 case 0:
7295 //no effect.
7296 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7297 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7298 break;
7299
7300 default:
7301
7302 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7303
7304 }
7305 }
7306
7307 } //end if stretched, but not masked
7308 1602 }
7309 else //not stretched
7310 {
7311
7312
2/2
✓ Branch 0 taken 223581 times.
✓ Branch 1 taken 10983 times.
234564 if(masked) //if masked, but not stretched
7313 {
7314
7315
2/2
✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 222576 times.
223581 if ( rot == 0 ) //if not rotated
7316 {
7317
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 18657 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 203919 times.
222576 switch(mode)
7318 {
7319 case 1:
7320 //transparent
7321 18657 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7322 18657 draw_trans_sprite(destBMP, subBmp, dx, dy);
7323 18657 break;
7324
7325
7326 case 2:
7327 //pivot?
7328 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7329 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7330 //Pivoting requires two more args
7331 break;
7332
7333 case 3:
7334 //pivot + trans
7335 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7336 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7337 break;
7338
7339 case 4:
7340 //flip v
7341 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7342 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7343 break;
7344
7345 case 5:
7346 //trans + v flip
7347 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7348 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7349 break;
7350
7351 case 6:
7352 //pivot + v flip
7353 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7354 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7355 break;
7356
7357 case 8:
7358 //vlip h
7359 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7360 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7361 break;
7362
7363 case 9:
7364 //trans + h flip
7365 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7366 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7367 break;
7368
7369 case 10:
7370 //flip H and pivot
7371 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7372 //return error cannot pivot and h flip
7373 break;
7374
7375 case 12:
7376 //vh flip
7377 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7378 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7379 break;
7380
7381 case 13:
7382 //trans + vh flip
7383 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7384 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7385 break;
7386
7387 case 14:
7388 //pivot and vh flip
7389 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7390 //return error cannot both pivot and vh flip
7391 break;
7392
7393 case 16:
7394 //lit
7395 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7396 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7397 break;
7398
7399 case 18:
7400 //pivot, lit
7401 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7402 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7403 break;
7404
7405 case 20:
7406 //lit + v flip
7407 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7408 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7409 break;
7410
7411 case 22:
7412 //Pivot, vflip, lit
7413 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7414 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7415 break;
7416
7417 case 24:
7418 //lit + h flip
7419 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7420 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7421 break;
7422
7423 case 26:
7424 //pivot + lit + hflip
7425 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7426 //return error cannot pivot, lit, and flip
7427 break;
7428
7429 case 28:
7430 //lit + vh flip
7431 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7432 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7433 break;
7434
7435 case 32: //gouraud
7436 //Probably not wort supporting.
7437 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7438 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7439 break;
7440
7441 case 0:
7442 //no effect
7443 203919 masked_blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7444 203919 break;
7445
7446
7447 default:
7448
7449 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7450
7451
7452 }
7453 222576 } //end if not rotated
7454
7455
2/2
✓ Branch 0 taken 222576 times.
✓ Branch 1 taken 1005 times.
223581 if ( rot != 0 ) //if rotated
7456 {
7457
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 1005 times.
✗ Branch 21 not taken.
1005 switch(mode)
7458 {
7459 case 1:
7460 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
7461 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7462
7463 break;
7464
7465 case 2:
7466 //pivot?
7467 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7468 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7469 //Pivoting requires two more args
7470 break;
7471
7472 case 3:
7473 //pivot + trans
7474 //return an error, cannot both rotate and pivot
7475 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7476 break;
7477
7478 case 4:
7479 //flip v
7480 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7481 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7482 break;
7483
7484 case 5:
7485 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
7486 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7487 break;
7488
7489 case 6:
7490 //pivot + v flip
7491 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7492 //return an error, cannot both rotate and pivot
7493 break;
7494
7495 case 8:
7496 //flip h
7497 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7498 //return an error, cannot both rotate and flip H
7499 break;
7500
7501 case 9:
7502 //trans + h flip
7503 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7504 //return an error, cannot rotate and flip a trans sprite
7505 break;
7506
7507 case 10:
7508 //flip H and pivot
7509 //return error cannot pivot and h flip
7510 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7511 break;
7512
7513 case 12:
7514 //vh flip
7515 //return an error, cannot rotate and VH flip a trans sprite
7516 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7517 break;
7518
7519 case 13:
7520 //trans + vh flip
7521 //return an error, cannot rotate and VH flip a trans sprite
7522 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7523 break;
7524
7525 case 14:
7526 //pivot and vh flip
7527 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7528 //return error cannot both pivot and vh flip
7529 break;
7530
7531 case 16:
7532 //lit
7533 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7534 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7535 break;
7536
7537 case 18:
7538 //pivot, lit
7539 //return an error, cannot both rotate and pivot
7540 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7541 break;
7542
7543 case 20:
7544 //lit + vflip
7545 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7546 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7547 break;
7548
7549 case 22:
7550 //Pivot, vflip, lit
7551 //return an error, cannot both rotate and pivot
7552 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7553 break;
7554
7555 case 24:
7556 //lit + h flip
7557 //return an error, cannot both rotate and H flip
7558 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7559 break;
7560
7561 case 26:
7562 //pivot + lit + hflip
7563 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7564 //return error cannot pivot, lit, and flip
7565 break;
7566
7567 case 28:
7568 //lit + vh flip
7569 //return an error, cannot both rotate and VH flip
7570 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7571 break;
7572
7573 case 32: //gouraud
7574 //Probably not wort supporting.
7575 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7576 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7577 break;
7578
7579 case 0:
7580 //no effect.
7581 1005 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7582 1005 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7583 1005 break;
7584
7585 default:
7586
7587 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7588
7589 }
7590 1005 } //end rtated, masked
7591 223581 } //end if masked
7592
7593 else //not masked, and not stretched; just blit
7594 {
7595
7596
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10983 times.
10983 if ( rot == 0 ) //if not rotated
7597 {
7598
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 5394 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5589 times.
10983 switch(mode)
7599 {
7600 case 1:
7601 //transparent
7602 5394 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7603 5394 draw_trans_sprite(destBMP, subBmp, dx, dy);
7604 5394 break;
7605
7606
7607 case 2:
7608 //pivot?
7609 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7610 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7611 //Pivoting requires two more args
7612 break;
7613
7614 case 3:
7615 //pivot + trans
7616 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7617 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7618 break;
7619
7620 case 4:
7621 //flip v
7622 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7623 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7624 break;
7625
7626 case 5:
7627 //trans + v flip
7628 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7629 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7630 break;
7631
7632 case 6:
7633 //pivot + v flip
7634 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7635 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7636 break;
7637
7638 case 8:
7639 //vlip h
7640 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7641 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7642 break;
7643
7644 case 9:
7645 //trans + h flip
7646 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7647 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7648 break;
7649
7650 case 10:
7651 //flip H and pivot
7652 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7653 //return error cannot pivot and h flip
7654 break;
7655
7656 case 12:
7657 //vh flip
7658 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7659 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7660 break;
7661
7662 case 13:
7663 //trans + vh flip
7664 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7665 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7666 break;
7667
7668 case 14:
7669 //pivot and vh flip
7670 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7671 //return error cannot both pivot and vh flip
7672 break;
7673
7674 case 16:
7675 //lit
7676 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7677 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7678 break;
7679
7680 case 18:
7681 //pivot, lit
7682 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7683 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7684 break;
7685
7686 case 20:
7687 //lit + v flip
7688 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7689 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7690 break;
7691
7692 case 22:
7693 //Pivot, vflip, lit
7694 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7695 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7696 break;
7697
7698 case 24:
7699 //lit + h flip
7700 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7701 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7702 break;
7703
7704 case 26:
7705 //pivot + lit + hflip
7706 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7707 //return error cannot pivot, lit, and flip
7708 break;
7709
7710 case 28:
7711 //lit + vh flip
7712 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7713 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7714 break;
7715
7716 case 32: //gouraud
7717 //Probably not wort supporting.
7718 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7719 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7720 break;
7721
7722 case 0:
7723 //no effect
7724 5589 blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7725 5589 break;
7726
7727
7728 default:
7729
7730 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7731
7732
7733 }
7734 10983 } //end if not rotated
7735
7736
1/2
✓ Branch 0 taken 10983 times.
✗ Branch 1 not taken.
10983 if ( rot != 0 ) //if rotated
7737 {
7738 switch(mode)
7739 {
7740 case 1:
7741 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
7742 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7743
7744 break;
7745
7746 case 2:
7747 //pivot?
7748 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7749 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7750 //Pivoting requires two more args
7751 break;
7752
7753 case 3:
7754 //pivot + trans
7755 //return an error, cannot both rotate and pivot
7756 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7757 break;
7758
7759 case 4:
7760 //flip v
7761 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7762 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7763 break;
7764
7765 case 5:
7766 //trans + v flip
7767 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7768 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7769 break;
7770
7771 case 6:
7772 //pivot + v flip
7773 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7774 //return an error, cannot both rotate and pivot
7775 break;
7776
7777 case 8:
7778 //flip h
7779 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7780 //return an error, cannot both rotate and flip H
7781 break;
7782
7783 case 9:
7784 //trans + h flip
7785 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7786 //return an error, cannot rotate and flip a trans sprite
7787 break;
7788
7789 case 10:
7790 //flip H and pivot
7791 //return error cannot pivot and h flip
7792 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7793 break;
7794
7795 case 12:
7796 //vh flip
7797 //return an error, cannot rotate and VH flip a trans sprite
7798 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7799 break;
7800
7801 case 13:
7802 //trans + vh flip
7803 //return an error, cannot rotate and VH flip a trans sprite
7804 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7805 break;
7806
7807 case 14:
7808 //pivot and vh flip
7809 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7810 //return error cannot both pivot and vh flip
7811 break;
7812
7813 case 16:
7814 //lit
7815 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7816 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7817 break;
7818
7819 case 18:
7820 //pivot, lit
7821 //return an error, cannot both rotate and pivot
7822 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7823 break;
7824
7825 case 20:
7826 //lit + vflip
7827 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7828 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7829 break;
7830
7831 case 22:
7832 //Pivot, vflip, lit
7833 //return an error, cannot both rotate and pivot
7834 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7835 break;
7836
7837 case 24:
7838 //lit + h flip
7839 //return an error, cannot both rotate and H flip
7840 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7841 break;
7842
7843 case 26:
7844 //pivot + lit + hflip
7845 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7846 //return error cannot pivot, lit, and flip
7847 break;
7848
7849 case 28:
7850 //lit + vh flip
7851 //return an error, cannot both rotate and VH flip
7852 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7853 break;
7854
7855 case 32: //gouraud
7856 //Probably not wort supporting.
7857 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7858 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7859 break;
7860
7861 case 0:
7862 //no effect.
7863 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7864 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7865 break;
7866
7867 default:
7868
7869 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7870
7871 }
7872 } //end if rotated
7873 } //end if not masked
7874 } //end if not stretched
7875
7876 //cleanup
7877
2/2
✓ Branch 0 taken 26530 times.
✓ Branch 1 taken 209636 times.
236166 if(subBmp)
7878 {
7879 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
7880 26530 destroy_bitmap(subBmp);
7881 26530 }
7882
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 236166 times.
236166 if (sbmp != sourceBitmap)
7883 {
7884 destroy_bitmap(sbmp);
7885 }
7886 236166 }
7887
7888
7889
7890 909 void bmp_do_blittor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
7891 {
7892 /*
7893 //sdci[1]=layer
7894 //sdci[2]=bitmap target
7895 //
7896 // -2 is the current Render Target
7897 // -1, this is the screen (framebuf).
7898 // 0: Render target 0
7899 // 1: Render target 1
7900 // 2: Render target 2
7901 // 3: Render target 3
7902 // 4: Render target 4
7903 // 5: Render target 5
7904 // 6: Render target 6
7905 // Otherwise: The pointer to a bitmap.
7906
7907 //sdci[3]=sourcex
7908 //sdci[4]=sourcey
7909 //sdci[5]=sourcew
7910 //sdci[6]=sourceh
7911 //sdci[7]=destx
7912 //sdci[8]=desty
7913 //sdci[9]=destw
7914 //sdci[10]=desth
7915 //sdci[11]=rotation/angle
7916 //scdi[12] = pivot cx
7917 //sdci[13] = pivot cy
7918 //scdi[14] = effect flags
7919 //sdci[17] Bitmap Pointer
7920
7921 // ZScript-side constant values:
7922 const int32_t BITDX_NORMAL = 0;
7923 const int32_t BITDX_TRANS = 1; //Translucent
7924 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
7925 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
7926 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
7927 //Note: Some modes cannot be combined. if a combination is not supported, an error
7928 // detailing this will be shown in allegro.log.
7929
7930 //scdi[15] = litcolour
7931 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7932 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
7933
7934 //sdci[16]=mask
7935
7936 */
7937
7938 909 int32_t srcyoffset = yoffset, srcxoffset = xoffset;
7939 909 int32_t bitmapIndex = sdci[2]/10000;
7940 909 int32_t usr_bitmap_index = sdci[2]-10;
7941 909 byte using_user_bitmap = 0;
7942 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
7943 //Z_scripterrlog("Blit() bitmapIndex is: %d\n", bitmapIndex);
7944 #if LOG_BMPBLIT_LEVEL > 0
7945 Z_scripterrlog("Blit() found a dest bitmap ID of: %d\n",bitmapIndex);
7946 #endif
7947
1/2
✓ Branch 0 taken 909 times.
✗ Branch 1 not taken.
909 if ( bitmapIndex > 10000 )
7948 {
7949 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
7950 }
7951
3/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 906 times.
909 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
7952 {
7953 906 bitmapIndex = usr_bitmap_index;
7954 906 using_user_bitmap = 1;
7955 906 srcyoffset = 0;
7956 906 }
7957
7958 909 int32_t sx = sdci[3]/10000;
7959 909 int32_t sy = sdci[4]/10000;
7960 909 int32_t sw = sdci[5]/10000;
7961 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
7962 909 int32_t sh = sdci[6]/10000;
7963 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
7964 909 int32_t dx = sdci[7]/10000;
7965 909 int32_t dy = sdci[8]/10000;
7966 909 int32_t dw = sdci[9]/10000;
7967 909 int32_t dh = sdci[10]/10000;
7968 909 float rot = sdci[11]/10000;
7969 909 int32_t cx = sdci[12]/10000;
7970 909 int32_t cy = sdci[13]/10000;
7971 909 int32_t mode = sdci[14]/10000;
7972 909 int32_t litcolour = sdci[15]/10000;
7973 909 bool masked = (sdci[16] != 0);
7974
7975 909 int32_t ref = 0;
7976
7977 //These should go down farther, should they not? -V
7978 //dx = dx + xoffset;
7979 //dy = dy + yoffset;
7980
7981
2/4
✓ Branch 0 taken 909 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 909 times.
909 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
7982
3/4
✓ Branch 0 taken 909 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 906 times.
909 if ( (bitmapIndex) != -2 && (bitmapIndex) != -1 ) srcyoffset = 0; //Don't crop.
7983 //Do we need to also check the render target and do the same thing if the
7984 //dest == -2 and the render target is not RT_SCREEN?
7985 909 dx = dx + xoffset;
7986 909 dy = dy + yoffset;
7987 909 sx = sx + srcxoffset;
7988 909 sy = sy + srcyoffset;
7989
7990 909 ref = sdci[17];
7991 //Z_scripterrlog("bitmap->blit() ref id this frame is: %d\n", ref);
7992 909 ref -=10;
7993 //Z_scripterrlog("bitmap->blit() modified ref id this frame is: %d\n", ref);
7994
7995
7996
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 909 times.
909 if ( ref <= 0 )
7997 {
7998 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
7999 return;
8000 }
8001 909 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
8002 #if LOG_BMPBLIT_LEVEL > 0
8003 Z_scripterrlog("bitmap->Blit() is trying to blit to ref: %d\n",sdci[17]);
8004 #endif
8005
1/2
✓ Branch 0 taken 909 times.
✗ Branch 1 not taken.
909 if(!sourceBitmap)
8006 {
8007 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
8008 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
8009 return;
8010 }
8011
8012 909 BITMAP *destBMP=NULL;
8013 //zprint2("RevBlit bitmap index is: %d\n",bitmapIndex);
8014
8015
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
909 switch(bitmapIndex)
8016 {
8017 case -2:
8018 {
8019 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
8020 //zprint2("current RT is: %d\n", curr_rt);
8021 if ( curr_rt >= 0 && curr_rt < 7 )
8022 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
8023 else destBMP = bmp; //screen
8024 break;
8025 }
8026 case -1:
8027 3 destBMP = bmp; //this is framebuf, by default
8028 3 break;
8029 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
8030 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
8031 //destBMP = framebuf; //Drawing to the screen.
8032 //break;
8033
8034 //1 through 6 are the old system bitmaps (Render Targets)
8035 case 0:
8036 case 1:
8037 case 2:
8038 case 3:
8039 case 4:
8040 case 5:
8041 case 6:
8042 {
8043 //This gets a render target.
8044 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
8045
8046 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
8047 //sdci[18] = bitmapIndex;
8048 break;
8049 }
8050 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
8051 default:
8052 {
8053 906 destBMP = scb.script_created_bitmaps[usr_bitmap_index].u_bmp;
8054 //sdci[18] = usr_bitmap_index;
8055
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( !scb.script_created_bitmaps[usr_bitmap_index].u_bmp )
8056 {
8057 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
8058 break;
8059 }
8060 }
8061 //FFCore.get_user_bitmap(bitmapIndex); break;
8062 906 }
8063
8064 #if LOG_BMPBLIT_LEVEL > 0
8065 Z_scripterrlog("bitmap->Blit() is trying to blit to dest bitmap ID: %d\n",bitmapIndex);
8066 #endif
8067
8068
8069
1/2
✓ Branch 0 taken 909 times.
✗ Branch 1 not taken.
909 if (!destBMP)
8070 {
8071 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
8072 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
8073 return;
8074 }
8075
8076 //bugfix
8077 //sx = vbound(sx, 0, sourceBitmap->w);
8078 #if LOG_BMPBLIT_LEVEL > 0
8079 Z_scripterrlog("Blit %s is: %d\n", "sx", sx);
8080 Z_scripterrlog("Blit %s is: %d\n", "source->w", sourceBitmap->w);
8081 #endif
8082 //sy = vbound(sy, 0, sourceBitmap->h);
8083 #if LOG_BMPBLIT_LEVEL > 0
8084 Z_scripterrlog("Blit %s is: %d\n", "sy", sy);
8085 Z_scripterrlog("Blit %s is: %d\n", "source->h", sourceBitmap->h);
8086 #endif
8087 //sw = vbound(sw, 0, sourceBitmap->w - sx); //keep the w/h within range as well
8088 #if LOG_BMPBLIT_LEVEL > 0
8089 Z_scripterrlog("Blit %s is: %d\n", "sw", sw);
8090 #endif
8091 //sh = vbound(sh, 0, sourceBitmap->h - sy);
8092 #if LOG_BMPBLIT_LEVEL > 0
8093 Z_scripterrlog("Blit %s is: %d\n", "sh", sh);
8094
8095 Z_scripterrlog("Blit %s is: %d\n", "dx", dx);
8096 Z_scripterrlog("Blit %s is: %d\n", "dy", dy);
8097 Z_scripterrlog("Blit %s is: %d\n", "dh", dh);
8098 Z_scripterrlog("Blit %s is: %d\n", "dw", dw);
8099 Z_scripterrlog("Blit %s is: %d\n", "yoffset", yoffset);
8100 #endif
8101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 909 times.
909 bool stretched = (sw != dw || sh != dh);
8102 //bool stretched = (sourceBitmap->w != destBMP->w || sourceBitmap->h != destBMP->h);
8103 #if LOG_BMPBLIT_LEVEL > 0
8104 Z_scripterrlog("Blit %s is: %s\n", "stretched", stretched ? "true" : "false");
8105 #endif
8106 //BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
8107
8108
8109
8110 909 BITMAP* newDest = sourceBitmap;
8111 909 BITMAP* newSource = destBMP; //Flip them.
8112
8113 909 BITMAP* subBmp = 0;
8114
8115 /* IDR what this was. -Z ( 17th April, 2019 )
8116 if ( bitmapIndex == -1 ) {
8117 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
8118 }
8119 */
8120
8121
2/4
✓ Branch 0 taken 909 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 909 times.
909 if(rot != 0 || mode != 0)
8122 {
8123 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
8124 clear_bitmap(subBmp);
8125
8126 if(!subBmp)
8127 {
8128 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
8129 return;
8130 }
8131 }
8132
8133
3/4
✓ Branch 0 taken 909 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 906 times.
909 if (sx + sw > destBMP->w || sy + sh > destBMP->h)
8134 {
8135 3 newSource = create_bitmap_ex(8, sw, sh);
8136 3 clear_bitmap(newSource);
8137 3 blit(destBMP, newSource, sx, sy, 0, 0, std::min(destBMP->w-sx, sw), std::min(destBMP->h-sy, sh));
8138 3 sx = 0;
8139 3 sy = 0;
8140 3 }
8141 //dx = dx + xoffset; //don't do this here!
8142 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
8143
8144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 909 times.
909 if(stretched)
8145 {
8146 if(masked)
8147 { //stretched and masked
8148 if ( rot == 0 )
8149 { //if not rotated
8150 switch(mode)
8151 {
8152 case 1:
8153 //transparent
8154 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8155 draw_trans_sprite(newDest, subBmp, dx, dy);
8156 break;
8157
8158
8159 case 2:
8160 //pivot?
8161 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8162 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8163 //Pivoting requires two more args
8164 break;
8165
8166 case 3:
8167 //pivot + trans
8168 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8169 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8170 break;
8171
8172 case 4:
8173 //flip v
8174 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8175 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8176 break;
8177
8178 case 5:
8179 //trans + v flip
8180 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8181 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8182 break;
8183
8184 case 6:
8185 //pivot + v flip
8186 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8187 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8188 break;
8189
8190 case 8:
8191 //vlip h
8192 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8193 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8194 break;
8195
8196 case 9:
8197 //trans + h flip
8198 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8199 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8200 break;
8201
8202 case 10:
8203 //flip H and pivot
8204 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8205 //return error cannot pivot and h flip
8206 break;
8207
8208 case 12:
8209 //vh flip
8210 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8211 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8212 break;
8213
8214 case 13:
8215 //trans + vh flip
8216 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8217 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8218 break;
8219
8220 case 14:
8221 //pivot and vh flip
8222 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8223 //return error cannot both pivot and vh flip
8224 break;
8225
8226 case 16:
8227 //lit
8228 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8229 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8230 break;
8231
8232 case 18:
8233 //pivot, lit
8234 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8235 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8236 break;
8237
8238 case 20:
8239 //lit + v flip
8240 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8241 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8242 break;
8243
8244 case 22:
8245 //Pivot, vflip, lit
8246 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8247 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8248 break;
8249
8250 case 24:
8251 //lit + h flip
8252 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8253 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8254 break;
8255
8256 case 26:
8257 //pivot + lit + hflip
8258 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8259 //return error cannot pivot, lit, and flip
8260 break;
8261
8262 case 28:
8263 //lit + vh flip
8264 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8265 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8266 break;
8267
8268 case 32: //gouraud
8269 //Probably not wort supporting.
8270 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8271 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8272 break;
8273
8274 case 0:
8275 //no effect
8276 masked_stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8277 break;
8278
8279
8280 default:
8281 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8282
8283
8284 }
8285 } //end if not rotated
8286
8287 if ( rot != 0 ) //if rotated
8288 {
8289 switch(mode)
8290 {
8291 case 1:
8292 //transparent
8293 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8294 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8295
8296 break;
8297
8298 case 2:
8299 //pivot?
8300 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8301 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8302 //Pivoting requires two more args
8303 break;
8304
8305 case 3:
8306 //pivot + trans
8307 //return an error, cannot both rotate and pivot
8308 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8309 break;
8310
8311 case 4:
8312 //flip v
8313 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8314 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8315 break;
8316
8317 case 5:
8318 //trans + v flip
8319 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8320 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8321 break;
8322
8323 case 6:
8324 //pivot + v flip
8325 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8326 //return an error, cannot both rotate and pivot
8327 break;
8328
8329 case 8:
8330 //flip h
8331 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8332 //return an error, cannot both rotate and flip H
8333 break;
8334
8335 case 9:
8336 //trans + h flip
8337 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8338 //return an error, cannot rotate and flip a trans sprite
8339 break;
8340
8341 case 10:
8342 //flip H and pivot
8343 //return error cannot pivot and h flip
8344 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8345 break;
8346
8347 case 12:
8348 //vh flip
8349 //return an error, cannot rotate and VH flip a trans sprite
8350 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8351 break;
8352
8353 case 13:
8354 //trans + vh flip
8355 //return an error, cannot rotate and VH flip a trans sprite
8356 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8357 break;
8358
8359 case 14:
8360 //pivot and vh flip
8361 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8362 //return error cannot both pivot and vh flip
8363 break;
8364
8365 case 16:
8366 //lit
8367 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8368 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8369 break;
8370
8371 case 18:
8372 //pivot, lit
8373 //return an error, cannot both rotate and pivot
8374 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8375 break;
8376
8377 case 20:
8378 //lit + vflip
8379 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8380 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8381 break;
8382
8383 case 22:
8384 //Pivot, vflip, lit
8385 //return an error, cannot both rotate and pivot
8386 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8387 break;
8388
8389 case 24:
8390 //lit + h flip
8391 //return an error, cannot both rotate and H flip
8392 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8393 break;
8394
8395 case 26:
8396 //pivot + lit + hflip
8397 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8398 //return error cannot pivot, lit, and flip
8399 break;
8400
8401 case 28:
8402 //lit + vh flip
8403 //return an error, cannot both rotate and VH flip
8404 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8405 break;
8406
8407 case 32: //gouraud
8408 //Probably not wort supporting.
8409 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8410 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8411 break;
8412
8413 case 0:
8414 //no effect.
8415 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8416 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8417 break;
8418
8419 default:
8420 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8421
8422 }
8423 }
8424 } //end if stretched and masked
8425
8426 else //stretched, not masked
8427 {
8428
8429
8430 if ( rot == 0 ) //if not rotated
8431 {
8432 switch(mode)
8433 {
8434 case 1:
8435 //transparent
8436 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8437 draw_trans_sprite(newDest, subBmp, dx, dy);
8438 break;
8439
8440
8441 case 2:
8442 //pivot?
8443 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8444 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8445 //Pivoting requires two more args
8446 break;
8447
8448 case 3:
8449 //pivot + trans
8450 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8451 pivot_sprite_trans(newDest, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
8452 break;
8453
8454 case 4:
8455 //flip v
8456 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8457 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8458 break;
8459
8460 case 5:
8461 //trans + v flip
8462 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8463 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8464 break;
8465
8466 case 6:
8467 //pivot + v flip
8468 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8469 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8470 break;
8471
8472 case 8:
8473 //vlip h
8474 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8475 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8476 break;
8477
8478 case 9:
8479 //trans + h flip
8480 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8481 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8482 break;
8483
8484 case 10:
8485 //flip H and pivot
8486 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8487 //return error cannot pivot and h flip
8488 break;
8489
8490 case 12:
8491 //vh flip
8492 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8493 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8494 break;
8495
8496 case 13:
8497 //trans + vh flip
8498 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8499 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8500 break;
8501
8502 case 14:
8503 //pivot and vh flip
8504 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8505 //return error cannot both pivot and vh flip
8506 break;
8507
8508 case 16:
8509 //lit
8510 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8511 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8512 break;
8513
8514 case 18:
8515 //pivot, lit
8516 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8517 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8518 break;
8519
8520 case 20:
8521 //lit + v flip
8522 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8523 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8524 break;
8525
8526 case 22:
8527 //Pivot, vflip, lit
8528 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8529 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8530 break;
8531
8532 case 24:
8533 //lit + h flip
8534 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8535 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8536 break;
8537
8538 case 26:
8539 //pivot + lit + hflip
8540 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8541 //return error cannot pivot, lit, and flip
8542 break;
8543
8544 case 28:
8545 //lit + vh flip
8546 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8547 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8548 break;
8549
8550 case 32: //gouraud
8551 //Probably not wort supporting.
8552 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8553 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8554 break;
8555
8556 case 0:
8557 //no effect
8558 stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8559 break;
8560
8561
8562 default:
8563 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8564
8565
8566 }
8567 } //end if not rotated
8568
8569 if ( rot != 0 ) //if rotated
8570 {
8571 switch(mode)
8572 {
8573 case 1:
8574 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8575 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8576
8577 break;
8578
8579 case 2:
8580 //pivot?
8581 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8582 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8583 //Pivoting requires two more args
8584 break;
8585
8586 case 3:
8587 //pivot + trans
8588 //return an error, cannot both rotate and pivot
8589 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8590 break;
8591
8592 case 4:
8593 //flip v
8594 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8595 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8596 break;
8597
8598 case 5:
8599 //trans + v flip
8600 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8601 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8602 break;
8603
8604 case 6:
8605 //pivot + v flip
8606 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8607 //return an error, cannot both rotate and pivot
8608 break;
8609
8610 case 8:
8611 //flip h
8612 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8613 //return an error, cannot both rotate and flip H
8614 break;
8615
8616 case 9:
8617 //trans + h flip
8618 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8619 //return an error, cannot rotate and flip a trans sprite
8620 break;
8621
8622 case 10:
8623 //flip H and pivot
8624 //return error cannot pivot and h flip
8625 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8626 break;
8627
8628 case 12:
8629 //vh flip
8630 //return an error, cannot rotate and VH flip a trans sprite
8631 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8632 break;
8633
8634 case 13:
8635 //trans + vh flip
8636 //return an error, cannot rotate and VH flip a trans sprite
8637 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8638 break;
8639
8640 case 14:
8641 //pivot and vh flip
8642 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8643 //return error cannot both pivot and vh flip
8644 break;
8645
8646 case 16:
8647 //lit
8648 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8649 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8650 break;
8651
8652 case 18:
8653 //pivot, lit
8654 //return an error, cannot both rotate and pivot
8655 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8656 break;
8657
8658 case 20:
8659 //lit + vflip
8660 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8661 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8662 break;
8663
8664 case 22:
8665 //Pivot, vflip, lit
8666 //return an error, cannot both rotate and pivot
8667 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8668 break;
8669
8670 case 24:
8671 //lit + h flip
8672 //return an error, cannot both rotate and H flip
8673 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8674 break;
8675
8676 case 26:
8677 //pivot + lit + hflip
8678 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8679 //return error cannot pivot, lit, and flip
8680 break;
8681
8682 case 28:
8683 //lit + vh flip
8684 //return an error, cannot both rotate and VH flip
8685 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8686 break;
8687
8688 case 32: //gouraud
8689 //Probably not wort supporting.
8690 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8691 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8692 break;
8693
8694 case 0:
8695 //no effect.
8696 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8697 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8698 break;
8699
8700 default:
8701 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8702
8703 }
8704 }
8705
8706 } //end if stretched, but not masked
8707 }
8708 else //not stretched
8709 {
8710
8711
2/2
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 3 times.
909 if(masked) //if masked, but not stretched
8712 {
8713
8714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if ( rot == 0 ) //if not rotated
8715 {
8716
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 906 times.
906 switch(mode)
8717 {
8718 case 1:
8719 //transparent
8720 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8721 draw_trans_sprite(newDest, subBmp, dx, dy);
8722 break;
8723
8724
8725 case 2:
8726 //pivot?
8727 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8728 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8729 //Pivoting requires two more args
8730 break;
8731
8732 case 3:
8733 //pivot + trans
8734 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8735 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8736 break;
8737
8738 case 4:
8739 //flip v
8740 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8741 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8742 break;
8743
8744 case 5:
8745 //trans + v flip
8746 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8747 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8748 break;
8749
8750 case 6:
8751 //pivot + v flip
8752 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8753 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8754 break;
8755
8756 case 8:
8757 //vlip h
8758 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8759 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8760 break;
8761
8762 case 9:
8763 //trans + h flip
8764 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8765 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8766 break;
8767
8768 case 10:
8769 //flip H and pivot
8770 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8771 //return error cannot pivot and h flip
8772 break;
8773
8774 case 12:
8775 //vh flip
8776 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8777 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8778 break;
8779
8780 case 13:
8781 //trans + vh flip
8782 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8783 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8784 break;
8785
8786 case 14:
8787 //pivot and vh flip
8788 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8789 //return error cannot both pivot and vh flip
8790 break;
8791
8792 case 16:
8793 //lit
8794 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8795 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8796 break;
8797
8798 case 18:
8799 //pivot, lit
8800 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8801 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8802 break;
8803
8804 case 20:
8805 //lit + v flip
8806 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8807 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8808 break;
8809
8810 case 22:
8811 //Pivot, vflip, lit
8812 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8813 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8814 break;
8815
8816 case 24:
8817 //lit + h flip
8818 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8819 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8820 break;
8821
8822 case 26:
8823 //pivot + lit + hflip
8824 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8825 //return error cannot pivot, lit, and flip
8826 break;
8827
8828 case 28:
8829 //lit + vh flip
8830 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8831 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8832 break;
8833
8834 case 32: //gouraud
8835 //Probably not wort supporting.
8836 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8837 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8838 break;
8839
8840 case 0:
8841 //no effect
8842 906 masked_blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8843 906 break;
8844
8845
8846 default:
8847 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8848
8849
8850 }
8851 906 } //end if not rotated
8852
8853
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( rot != 0 ) //if rotated
8854 {
8855 switch(mode)
8856 {
8857 case 1:
8858 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //transparent
8859 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8860
8861 break;
8862
8863 case 2:
8864 //pivot?
8865 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8866 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8867 //Pivoting requires two more args
8868 break;
8869
8870 case 3:
8871 //pivot + trans
8872 //return an error, cannot both rotate and pivot
8873 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8874 break;
8875
8876 case 4:
8877 //flip v
8878 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8879 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8880 break;
8881
8882 case 5:
8883 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
8884 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8885 break;
8886
8887 case 6:
8888 //pivot + v flip
8889 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8890 //return an error, cannot both rotate and pivot
8891 break;
8892
8893 case 8:
8894 //flip h
8895 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8896 //return an error, cannot both rotate and flip H
8897 break;
8898
8899 case 9:
8900 //trans + h flip
8901 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8902 //return an error, cannot rotate and flip a trans sprite
8903 break;
8904
8905 case 10:
8906 //flip H and pivot
8907 //return error cannot pivot and h flip
8908 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8909 break;
8910
8911 case 12:
8912 //vh flip
8913 //return an error, cannot rotate and VH flip a trans sprite
8914 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8915 break;
8916
8917 case 13:
8918 //trans + vh flip
8919 //return an error, cannot rotate and VH flip a trans sprite
8920 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8921 break;
8922
8923 case 14:
8924 //pivot and vh flip
8925 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8926 //return error cannot both pivot and vh flip
8927 break;
8928
8929 case 16:
8930 //lit
8931 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8932 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8933 break;
8934
8935 case 18:
8936 //pivot, lit
8937 //return an error, cannot both rotate and pivot
8938 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8939 break;
8940
8941 case 20:
8942 //lit + vflip
8943 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8944 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8945 break;
8946
8947 case 22:
8948 //Pivot, vflip, lit
8949 //return an error, cannot both rotate and pivot
8950 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8951 break;
8952
8953 case 24:
8954 //lit + h flip
8955 //return an error, cannot both rotate and H flip
8956 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8957 break;
8958
8959 case 26:
8960 //pivot + lit + hflip
8961 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8962 //return error cannot pivot, lit, and flip
8963 break;
8964
8965 case 28:
8966 //lit + vh flip
8967 //return an error, cannot both rotate and VH flip
8968 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8969 break;
8970
8971 case 32: //gouraud
8972 //Probably not wort supporting.
8973 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8974 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8975 break;
8976
8977 case 0:
8978 //no effect.
8979 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8980 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8981 break;
8982
8983 default:
8984 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8985
8986 }
8987 } //end rtated, masked
8988 906 } //end if masked
8989
8990 else //not masked, and not stretched; just blit
8991 {
8992
8993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( rot == 0 ) //if not rotated
8994 {
8995
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
3 switch(mode)
8996 {
8997 case 1:
8998 //transparent
8999 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9000 draw_trans_sprite(newDest, subBmp, dx, dy);
9001 break;
9002
9003
9004 case 2:
9005 //pivot?
9006 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9007 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9008 //Pivoting requires two more args
9009 break;
9010
9011 case 3:
9012 //pivot + trans
9013 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9014 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9015 break;
9016
9017 case 4:
9018 //flip v
9019 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9020 draw_sprite_v_flip(newDest, subBmp, dx, dy);
9021 break;
9022
9023 case 5:
9024 //trans + v flip
9025 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9026 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9027 break;
9028
9029 case 6:
9030 //pivot + v flip
9031 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9032 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9033 break;
9034
9035 case 8:
9036 //vlip h
9037 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9038 draw_sprite_h_flip(newDest, subBmp, dx, dy);
9039 break;
9040
9041 case 9:
9042 //trans + h flip
9043 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9044 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9045 break;
9046
9047 case 10:
9048 //flip H and pivot
9049 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
9050 //return error cannot pivot and h flip
9051 break;
9052
9053 case 12:
9054 //vh flip
9055 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9056 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
9057 break;
9058
9059 case 13:
9060 //trans + vh flip
9061 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9062 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9063 break;
9064
9065 case 14:
9066 //pivot and vh flip
9067 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9068 //return error cannot both pivot and vh flip
9069 break;
9070
9071 case 16:
9072 //lit
9073 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9074 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
9075 break;
9076
9077 case 18:
9078 //pivot, lit
9079 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9080 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9081 break;
9082
9083 case 20:
9084 //lit + v flip
9085 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9086 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9087 break;
9088
9089 case 22:
9090 //Pivot, vflip, lit
9091 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9092 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9093 break;
9094
9095 case 24:
9096 //lit + h flip
9097 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9098 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9099 break;
9100
9101 case 26:
9102 //pivot + lit + hflip
9103 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
9104 //return error cannot pivot, lit, and flip
9105 break;
9106
9107 case 28:
9108 //lit + vh flip
9109 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9110 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9111 break;
9112
9113 case 32: //gouraud
9114 //Probably not wort supporting.
9115 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9116 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9117 break;
9118
9119 case 0:
9120 //no effect
9121 3 blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
9122 3 break;
9123
9124
9125 default:
9126 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9127
9128
9129 }
9130 3 } //end if not rotated
9131
9132
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( rot != 0 ) //if rotated
9133 {
9134 switch(mode)
9135 {
9136 case 1:
9137 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);//transparent
9138 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9139
9140 break;
9141
9142 case 2:
9143 //pivot?
9144 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9145 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9146 //Pivoting requires two more args
9147 break;
9148
9149 case 3:
9150 //pivot + trans
9151 //return an error, cannot both rotate and pivot
9152 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9153 break;
9154
9155 case 4:
9156 //flip v
9157 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9158 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9159 break;
9160
9161 case 5:
9162 //trans + v flip
9163 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9164 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9165 break;
9166
9167 case 6:
9168 //pivot + v flip
9169 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9170 //return an error, cannot both rotate and pivot
9171 break;
9172
9173 case 8:
9174 //flip h
9175 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
9176 //return an error, cannot both rotate and flip H
9177 break;
9178
9179 case 9:
9180 //trans + h flip
9181 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
9182 //return an error, cannot rotate and flip a trans sprite
9183 break;
9184
9185 case 10:
9186 //flip H and pivot
9187 //return error cannot pivot and h flip
9188 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
9189 break;
9190
9191 case 12:
9192 //vh flip
9193 //return an error, cannot rotate and VH flip a trans sprite
9194 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9195 break;
9196
9197 case 13:
9198 //trans + vh flip
9199 //return an error, cannot rotate and VH flip a trans sprite
9200 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9201 break;
9202
9203 case 14:
9204 //pivot and vh flip
9205 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9206 //return error cannot both pivot and vh flip
9207 break;
9208
9209 case 16:
9210 //lit
9211 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9212 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9213 break;
9214
9215 case 18:
9216 //pivot, lit
9217 //return an error, cannot both rotate and pivot
9218 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9219 break;
9220
9221 case 20:
9222 //lit + vflip
9223 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9224 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9225 break;
9226
9227 case 22:
9228 //Pivot, vflip, lit
9229 //return an error, cannot both rotate and pivot
9230 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9231 break;
9232
9233 case 24:
9234 //lit + h flip
9235 //return an error, cannot both rotate and H flip
9236 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
9237 break;
9238
9239 case 26:
9240 //pivot + lit + hflip
9241 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
9242 //return error cannot pivot, lit, and flip
9243 break;
9244
9245 case 28:
9246 //lit + vh flip
9247 //return an error, cannot both rotate and VH flip
9248 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9249 break;
9250
9251 case 32: //gouraud
9252 //Probably not wort supporting.
9253 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9254 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9255 break;
9256
9257 case 0:
9258 //no effect.
9259 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9260 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9261 break;
9262
9263 default:
9264 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9265
9266 }
9267 } //end if rotated
9268 } //end if not masked
9269 } //end if not stretched
9270
9271 //cleanup
9272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 909 times.
909 if(subBmp)
9273 {
9274 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
9275 destroy_bitmap(subBmp);
9276 }
9277
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 906 times.
909 if(newSource != destBMP)
9278 {
9279 3 destroy_bitmap(newSource);
9280 3 }
9281 909 }
9282
9283
9284 void bmp_do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
9285 {
9286
9287 //sdci[1]=layer
9288 //sdci[2]=pos[12]
9289 //sdci[3]=uv[8]
9290 //sdci[4]=color[4]
9291 //sdci[5]=size[2]
9292 //sdci[6]=flip
9293 //sdci[7]=tile/combo
9294 //sdci[8]=polytype
9295 //sdci[9] = other bitmap as texture
9296 //sdci[17] Bitmap Pointer
9297 if ( sdci[17] <= 0 )
9298 {
9299 Z_scripterrlog("bitmap->Quad3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
9300 return;
9301 }
9302 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9303 if ( refbmp == NULL ) return;
9304
9305 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
9306
9307 if(!v_ptr)
9308 {
9309 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
9310 return;
9311 }
9312
9313 std::vector<int32_t> &v = *v_ptr;
9314
9315 if(v.empty())
9316 return;
9317
9318 int32_t* pos = &v[0];
9319 int32_t* uv = &v[12];
9320 int32_t* col = &v[20];
9321 int32_t* size = &v[24];
9322
9323 int32_t w = size[0]; //magic numerical constants... yuck.
9324 int32_t h = size[1];
9325 int32_t flip = (sdci[6]/10000)&3;
9326 int32_t tile = sdci[7]/10000;
9327 int32_t polytype = sdci[8]/10000;
9328 int32_t quad_render_source = sdci[9]-10;
9329 Z_scripterrlog("Quad3D texture is %d\n", quad_render_source);
9330
9331 polytype = vbound(polytype, 0, 14);
9332
9333 int32_t tex_width = w*16;
9334 int32_t tex_height = h*16;
9335
9336 bool mustDestroyBmp = false;
9337 BITMAP *tex=NULL;
9338
9339
9340 bool tex_is_bitmap = ( sdci[9] != 0 );
9341 //Z_scripterrlog("sdci[9] is %d\n", quad_render_source);
9342 //Z_scripterrlog("sdci[17] is %d\n", sdci[17]-10);
9343 BITMAP *bmptexture;
9344
9345 if ( tex_is_bitmap ) bmptexture = FFCore.GetScriptBitmap(quad_render_source);
9346
9347 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9348
9349
9350 if ( !tex_is_bitmap )
9351 {
9352 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
9353
9354 if(!tex)
9355 {
9356 mustDestroyBmp = true;
9357 tex = create_bitmap_ex(8, tex_width, tex_height);
9358 clear_bitmap(tex);
9359 }
9360 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
9361 {
9362 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
9363 return; //non power of two error
9364 }
9365 if(tile > 0) // TILE
9366 {
9367 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
9368 }
9369 else // COMBO
9370 {
9371 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
9372 const int32_t tiletodraw = combo_tile(c, 0, 0);
9373 flip = flip ^ c.flip;
9374
9375 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
9376 }
9377
9378 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9379 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9380 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9381 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
9382
9383 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
9384 if(mustDestroyBmp)
9385 destroy_bitmap(tex);
9386 }
9387 else
9388 {
9389
9390 if ( !bmptexture )
9391 {
9392 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Quad3D()");
9393 tex_is_bitmap = 0;
9394 return;
9395 }
9396 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9397 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9398 if ( !isPowerOfTwo(h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
9399 if ( !isPowerOfTwo(w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
9400
9401 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9402 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9403 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9404 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
9405
9406 BITMAP *foo = create_bitmap_ex(8, 256, 176);
9407
9408 //quad3d_f(refbmp, polytype, foo, &V1, &V2, &V3, &V4);
9409 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
9410 destroy_bitmap(foo);
9411
9412 }
9413
9414
9415
9416 }
9417
9418
9419
9420 void bmp_do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
9421 {
9422 //sdci[1]=layer
9423 //sdci[2]=pos[9]
9424 //sdci[3]=uv[6]
9425 //sdci[4]=color[3]
9426 //sdci[5]=size[2]
9427 //sdci[6]=flip
9428 //sdci[7]=tile/combo
9429 //sdci[8]=polytype
9430 //sdci[9] bitmap as texture
9431 //sdci[17] Bitmap Pointer
9432 if ( sdci[17] <= 0 )
9433 {
9434 Z_scripterrlog("bitmap->Triangle3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
9435 return;
9436 }
9437 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9438 if ( refbmp == NULL ) return;
9439
9440 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
9441
9442 if(!v_ptr)
9443 {
9444 al_trace("bitmap->Triangle3d: Vector pointer is null! Internal error. \n");
9445 return;
9446 }
9447
9448 std::vector<int32_t> &v = *v_ptr;
9449
9450 if(v.empty())
9451 return;
9452
9453 int32_t* pos = &v[0];
9454 int32_t* uv = &v[9];
9455 int32_t* col = &v[15];
9456 int32_t* size = &v[18];
9457
9458 int32_t w = size[0]; //magic numerical constants... yuck.
9459 int32_t h = size[1];
9460 int32_t flip = (sdci[6]/10000)&3;
9461 int32_t tile = sdci[7]/10000;
9462 int32_t polytype = sdci[8]/10000;
9463 int32_t quad_render_source = sdci[9]-10;
9464 polytype = vbound(polytype, 0, 14);
9465
9466 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
9467 {
9468 Z_message("bitmap->Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
9469 return; //non power of two error
9470 }
9471
9472 int32_t tex_width = w*16;
9473 int32_t tex_height = h*16;
9474
9475 bool mustDestroyBmp = false;
9476 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
9477
9478 if(!tex)
9479 {
9480 mustDestroyBmp = true;
9481 tex = create_bitmap_ex(8, tex_width, tex_height);
9482 clear_bitmap(tex);
9483 }
9484
9485 bool tex_is_bitmap = ( sdci[9] != 0 );
9486 BITMAP *bmptexture=NULL;
9487 if ( tex_is_bitmap )
9488 {
9489 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
9490 if ( !bmptexture )
9491 {
9492 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
9493 tex_is_bitmap = 0;
9494 }
9495 }
9496
9497 if ( !tex_is_bitmap )
9498 {
9499 if(tile > 0) // TILE
9500 {
9501 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
9502 }
9503 else // COMBO
9504 {
9505 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
9506 const int32_t tiletodraw = combo_tile(c, 0, 0);
9507 flip = flip ^ c.flip;
9508
9509 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
9510 }
9511
9512 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9513 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9514 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9515
9516 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
9517 }
9518 else
9519 {
9520 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9521 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9522 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
9523 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
9524
9525 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9526 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9527 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9528
9529 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
9530
9531
9532 }
9533 if(mustDestroyBmp)
9534 destroy_bitmap(tex);
9535
9536 }
9537
9538
9539 bool is_layer_transparent(const mapscr& m, int32_t layer)
9540 {
9541 layer = vbound(layer, 0, 5);
9542 return m.layeropacity[layer] == 128;
9543 }
9544
9545 4328553 mapscr *getmapscreen(int32_t map_index, int32_t screen_index, int32_t layer) //returns NULL for invalid or non-existent layer
9546 {
9547 mapscr *base_screen;
9548 4328553 int32_t index = map_index*MAPSCRS+screen_index;
9549
9550
2/4
✓ Branch 0 taken 4328553 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4328553 times.
4328553 if((uint32_t)layer > 6 || (uint32_t)index >= TheMaps.size())
9551 return NULL;
9552
9553
2/2
✓ Branch 0 taken 3543647 times.
✓ Branch 1 taken 784906 times.
4328553 if(layer != 0)
9554 {
9555 784906 layer = layer - 1;
9556
9557 784906 base_screen=&(TheMaps[index]);
9558
9559
2/2
✓ Branch 0 taken 748179 times.
✓ Branch 1 taken 36727 times.
784906 if(base_screen->layermap[layer]==0)
9560 36727 return NULL;
9561
9562 748179 index=(base_screen->layermap[layer]-1)*MAPSCRS+base_screen->layerscreen[layer];
9563
9564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748179 times.
748179 if((uint32_t)index >= TheMaps.size()) // Might as well make sure
9565 return NULL;
9566 748179 }
9567
9568 4291826 return &(TheMaps[index]);
9569 4328553 }
9570
9571 28786 void draw_mapscr(BITMAP *b, const mapscr& m, int32_t x, int32_t y, bool transparent)
9572 {
9573
2/2
✓ Branch 0 taken 5066336 times.
✓ Branch 1 taken 28786 times.
5095122 for(int32_t i(0); i < 176; ++i)
9574 {
9575 5066336 const int32_t x2 = ((i&15)<<4) + x;
9576 5066336 const int32_t y2 = (i&0xF0) + y;
9577
9578 //const newcombo & c = combobuf[ m.data[i] ];
9579 /*
9580 newcombo c = combobuf[m.data[i]];
9581 int32_t csets[4];
9582 int32_t cofs = c.csets&15;
9583
9584 if(cofs&8)
9585 cofs |= ~int32_t(0xF);
9586
9587 for(int32_t i=0; i<4; ++i)
9588 csets[i] = c.csets&(16<<i) ? cset + cofs : cset;
9589
9590
9591 const int32_t tile = combo_tile(c, x2, y2);
9592 */
9593
9594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5066336 times.
5066336 if(transparent)
9595 {
9596 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
9597 overcomboblocktranslucent(b, x2, y2, m.data[i], m.cset[i], 1, 1, 128);
9598 //overtiletranslucent16(b, tile, x2, y2, m.cset[i], c.flip, 128);
9599 }
9600 else
9601 {
9602 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
9603 5066336 overcomboblock(b, x2, y2, m.data[i], m.cset[i], 1, 1);
9604 //overtile16(b, tile, x2, y2, m.cset[i], c.flip);
9605 }
9606 5066336 }
9607 28786 }
9608
9609 void draw_map_solidity(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9610 {
9611 BITMAP* square = create_bitmap_ex(8,16,16);
9612
9613 for(int32_t i(0); i < 176; ++i)
9614 {
9615 const int32_t x2 = ((i&15)<<4) + x;
9616 const int32_t y2 = (i&0xF0) + y;
9617 //Blit the palette index of the solidity value.
9618 //int32_t col = (combobuf[m.data[i]].walk&15);
9619 //if ( col != 0 )
9620 //{
9621 // Z_scripterrlog("Position %d has a solidity value of %d.\n", i, col);
9622 //
9623 //}
9624 clear_to_color(square,(combobuf[m.data[i]].walk&15));
9625 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9626 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9627 }
9628 destroy_bitmap(square);
9629 }
9630
9631 void do_bmpdrawscreen_solidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9632 {
9633 //sdci[1]=layer
9634 //sdci[2]=map
9635 //sdci[3]=screen
9636 //sdci[4]=x
9637 //sdci[5]=y
9638 //sdci[6]=rotation
9639 //sdci[17] Bitmap Pointer
9640
9641 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9642 if ( refbmp == NULL ) return;
9643
9644 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9645
9646 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9647 int32_t scrn = sdci[3]/10000;
9648 int32_t x = sdci[4]/10000;
9649 int32_t y = sdci[5]/10000;
9650 int32_t x1 = x + xoffset;
9651 int32_t y1 = y + yoffset;
9652 int32_t rotation = sdci[6]/10000;
9653
9654 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9655
9656 if(index >= TheMaps.size())
9657 {
9658 al_trace("DrawScreen: invalid map or screen index. \n");
9659 return;
9660 }
9661
9662 const mapscr & m = TheMaps[index];
9663
9664
9665 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
9666 if ( refbmp == NULL ) return;
9667
9668 if(rotation != 0)
9669 b = script_drawing_commands.AquireSubBitmap(256, 176);
9670
9671 //draw layer 0
9672 draw_map_solidity(b, m, x1, y1);
9673 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS))
9674 {
9675 for(int32_t i(0); i < 6; ++i)
9676 {
9677 if(m.layermap[i] == 0) continue;
9678
9679 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9680
9681 if(layer_screen_index >= TheMaps.size())
9682 continue;
9683
9684 //draw valid layers
9685 draw_map_solidity(b, TheMaps[ layer_screen_index ], x1, y1);
9686 }
9687 }
9688
9689 if(rotation != 0) // rotate
9690 {
9691 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9692 script_drawing_commands.ReleaseSubBitmap(b);
9693 }
9694 }
9695
9696 void draw_map_solid(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9697 {
9698 BITMAP* square = create_bitmap_ex(8,16,16);
9699 BITMAP* subsquare = create_bitmap_ex(8,16,16);
9700 clear_to_color(subsquare,1);
9701
9702 for(int32_t i(0); i < 176; ++i)
9703 {
9704 const int32_t x2 = ((i&15)<<4) + x;
9705 const int32_t y2 = (i&0xF0) + y;
9706 //Blit the palette index of the solidity value.
9707 //int32_t col = (combobuf[m.data[i]].walk&15);
9708 //if ( col != 0 )
9709 //{
9710 // Z_scripterrlog("Position %d has a solidity value of %d.\n", i, col);
9711 //
9712 //}
9713 clear_bitmap(square);
9714 int32_t sol = (combobuf[m.data[i]].walk);
9715 //al_trace("Solidity is: %d.\n", sol);
9716 if ( sol & 1 )
9717 {
9718 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
9719 }
9720 if ( sol & 2 )
9721 {
9722 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
9723 }
9724 if ( sol & 4 )
9725 {
9726 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
9727 }
9728 if ( sol &8 ) {
9729 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
9730 }
9731
9732 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9733 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9734 }
9735 destroy_bitmap(square);
9736 destroy_bitmap(subsquare);
9737 }
9738
9739 void do_bmpdrawscreen_solidr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9740 {
9741 //sdci[1]=layer
9742 //sdci[2]=map
9743 //sdci[3]=screen
9744 //sdci[4]=x
9745 //sdci[5]=y
9746 //sdci[6]=rotation
9747 //sdci[17] Bitmap Pointer
9748
9749 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9750 if ( refbmp == NULL ) return;
9751
9752 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9753
9754 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9755 int32_t scrn = sdci[3]/10000;
9756 int32_t x = sdci[4]/10000;
9757 int32_t y = sdci[5]/10000;
9758 int32_t x1 = x + xoffset;
9759 int32_t y1 = y + yoffset;
9760 int32_t rotation = sdci[6]/10000;
9761
9762 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9763
9764 if(index >= TheMaps.size())
9765 {
9766 al_trace("DrawScreen: invalid map or screen index. \n");
9767 return;
9768 }
9769
9770 const mapscr & m = TheMaps[index];
9771
9772
9773 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
9774 if ( refbmp == NULL ) return;
9775
9776 if(rotation != 0)
9777 b = script_drawing_commands.AquireSubBitmap(256, 176);
9778
9779 //draw layer 0
9780 draw_map_solid(b, m, x1, y1);
9781
9782 for(int32_t i(0); i < 6; ++i) //This one doesn't need the QR; it works just fine.
9783 {
9784 if(m.layermap[i] == 0) continue;
9785
9786 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9787
9788 if(layer_screen_index >= TheMaps.size())
9789 continue;
9790
9791 //draw valid layers
9792 draw_map_solid(b, TheMaps[ layer_screen_index ], x1, y1);
9793 }
9794
9795 if(rotation != 0) // rotate
9796 {
9797 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9798 script_drawing_commands.ReleaseSubBitmap(b);
9799 }
9800 }
9801
9802 1024 void draw_map_cflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9803 {
9804 1024 BITMAP* square = create_bitmap_ex(8,16,16);
9805
9806
2/2
✓ Branch 0 taken 180224 times.
✓ Branch 1 taken 1024 times.
181248 for(int32_t i(0); i < 176; ++i)
9807 {
9808 180224 const int32_t x2 = ((i&15)<<4) + x;
9809 180224 const int32_t y2 = (i&0xF0) + y;
9810 //Blit the palette index of the solidity value.
9811 180224 clear_to_color(square,m.sflag[i]);
9812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180224 times.
180224 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9813 180224 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9814 180224 }
9815 1024 destroy_bitmap(square);
9816 1024 }
9817
9818 1024 void do_bmpdrawscreen_cflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9819 {
9820 //sdci[1]=layer
9821 //sdci[2]=map
9822 //sdci[3]=screen
9823 //sdci[4]=x
9824 //sdci[5]=y
9825 //sdci[6]=rotation
9826 //sdci[17] Bitmap Pointer
9827
9828 1024 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9829
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
9830
9831
2/4
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1024 times.
1024 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9832
9833 1024 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9834 1024 int32_t scrn = sdci[3]/10000;
9835 1024 int32_t x = sdci[4]/10000;
9836 1024 int32_t y = sdci[5]/10000;
9837 1024 int32_t x1 = x + xoffset;
9838 1024 int32_t y1 = y + yoffset;
9839 1024 int32_t rotation = sdci[6]/10000;
9840
9841 1024 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9842
9843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024 times.
1024 if(index >= TheMaps.size())
9844 {
9845 al_trace("DrawScreen: invalid map or screen index. \n");
9846 return;
9847 }
9848
9849 1024 const mapscr & m = TheMaps[index];
9850
9851
9852 1024 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
9853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024 times.
1024 if ( refbmp == NULL ) return;
9854
9855
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0)
9856 b = script_drawing_commands.AquireSubBitmap(256, 176);
9857
9858 //draw layer 0
9859 1024 draw_map_cflag(b, m, x1, y1);
9860
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS))
9861 {
9862 for(int32_t i(0); i < 6; ++i)
9863 {
9864 if(m.layermap[i] == 0) continue;
9865
9866 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9867
9868 if(layer_screen_index >= TheMaps.size())
9869 continue;
9870
9871 //draw valid layers
9872 draw_map_cflag(b, TheMaps[ layer_screen_index ], x1, y1);
9873 }
9874 }
9875
9876
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0) // rotate
9877 {
9878 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9879 script_drawing_commands.ReleaseSubBitmap(b);
9880 }
9881 1024 }
9882
9883
9884 void draw_map_combotype(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9885 {
9886 BITMAP* square = create_bitmap_ex(8,16,16);
9887
9888 for(int32_t i(0); i < 176; ++i)
9889 {
9890 const int32_t x2 = ((i&15)<<4) + x;
9891 const int32_t y2 = (i&0xF0) + y;
9892 //Blit the palette index of the solidity value.
9893 clear_to_color(square,(combobuf[m.data[i]].type));
9894 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9895 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9896 }
9897 destroy_bitmap(square);
9898 }
9899
9900 void do_bmpdrawscreen_ctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9901 {
9902 //sdci[1]=layer
9903 //sdci[2]=map
9904 //sdci[3]=screen
9905 //sdci[4]=x
9906 //sdci[5]=y
9907 //sdci[6]=rotation
9908 //sdci[17] Bitmap Pointer
9909
9910 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9911 if ( refbmp == NULL ) return;
9912
9913 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9914
9915 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9916 int32_t scrn = sdci[3]/10000;
9917 int32_t x = sdci[4]/10000;
9918 int32_t y = sdci[5]/10000;
9919 int32_t x1 = x + xoffset;
9920 int32_t y1 = y + yoffset;
9921 int32_t rotation = sdci[6]/10000;
9922
9923 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9924
9925 if(index >= TheMaps.size())
9926 {
9927 al_trace("DrawScreen: invalid map or screen index. \n");
9928 return;
9929 }
9930
9931 const mapscr & m = TheMaps[index];
9932
9933
9934 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
9935 if ( refbmp == NULL ) return;
9936
9937 if(rotation != 0)
9938 b = script_drawing_commands.AquireSubBitmap(256, 176);
9939
9940 //draw layer 0
9941 draw_map_combotype(b, m, x1, y1);
9942
9943 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS))
9944 {
9945 for(int32_t i(0); i < 6; ++i)
9946 {
9947 if(m.layermap[i] == 0) continue;
9948
9949 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9950
9951 if(layer_screen_index >= TheMaps.size())
9952 continue;
9953
9954 //draw valid layers
9955 draw_map_combotype(b, TheMaps[ layer_screen_index ], x1, y1);
9956 }
9957 }
9958
9959 if(rotation != 0) // rotate
9960 {
9961 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9962 script_drawing_commands.ReleaseSubBitmap(b);
9963 }
9964 }
9965
9966
9967 void draw_map_comboiflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9968 {
9969 BITMAP* square = create_bitmap_ex(8,16,16);
9970
9971 for(int32_t i(0); i < 176; ++i)
9972 {
9973 const int32_t x2 = ((i&15)<<4) + x;
9974 const int32_t y2 = (i&0xF0) + y;
9975 //Blit the palette index of the solidity value.
9976 clear_to_color(square,(combobuf[m.data[i]].flag));
9977 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9978 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9979 }
9980 destroy_bitmap(square);
9981 }
9982
9983 void do_bmpdrawscreen_ciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9984 {
9985 //sdci[1]=layer
9986 //sdci[2]=map
9987 //sdci[3]=screen
9988 //sdci[4]=x
9989 //sdci[5]=y
9990 //sdci[6]=rotation
9991 //sdci[17] Bitmap Pointer
9992
9993 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
9994 if ( refbmp == NULL ) return;
9995
9996 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9997
9998 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9999 int32_t scrn = sdci[3]/10000;
10000 int32_t x = sdci[4]/10000;
10001 int32_t y = sdci[5]/10000;
10002 int32_t x1 = x + xoffset;
10003 int32_t y1 = y + yoffset;
10004 int32_t rotation = sdci[6]/10000;
10005
10006 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10007
10008 if(index >= TheMaps.size())
10009 {
10010 al_trace("DrawScreen: invalid map or screen index. \n");
10011 return;
10012 }
10013
10014 const mapscr & m = TheMaps[index];
10015
10016
10017 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
10018 if ( refbmp == NULL ) return;
10019
10020 if(rotation != 0)
10021 b = script_drawing_commands.AquireSubBitmap(256, 176);
10022
10023 //draw layer 0
10024 draw_map_comboiflag(b, m, x1, y1);
10025
10026 if (get_bit(quest_rules, qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10027 {
10028 for(int32_t i(0); i < 6; ++i)
10029 {
10030 if(m.layermap[i] == 0) continue;
10031
10032 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10033
10034 if(layer_screen_index >= TheMaps.size())
10035 continue;
10036
10037 //draw valid layers
10038 draw_map_comboiflag(b, TheMaps[ layer_screen_index ], x1, y1);
10039 }
10040 }
10041
10042 if(rotation != 0) // rotate
10043 {
10044 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10045 script_drawing_commands.ReleaseSubBitmap(b);
10046 }
10047 }
10048
10049 4327380 void do_drawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10050 {
10051 //sdci[1]=layer
10052 //sdci[2]=map
10053 //sdci[3]=screen
10054 //sdci[4]=layer
10055 //sdci[5]=x
10056 //sdci[6]=y
10057 //sdci[7]=rotation
10058 //sdci[8]=opacity
10059
10060 4327380 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10061 4327380 int32_t scrn = sdci[3]/10000;
10062 4327380 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10063 4327380 int32_t x = sdci[5]/10000;
10064 4327380 int32_t y = sdci[6]/10000;
10065 4327380 int32_t x1 = x + xoffset;
10066 4327380 int32_t y1 = y + yoffset;
10067 4327380 int32_t rotation = sdci[7]/10000;
10068 4327380 int32_t opacity = sdci[8]/10000;
10069
10070 4327380 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10071 4327380 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10072
10073
2/2
✓ Branch 0 taken 4290659 times.
✓ Branch 1 taken 36721 times.
4327380 if(!m) //no need to log it.
10074 36721 return;
10075
10076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4290659 times.
4290659 if(index >= TheMaps.size())
10077 {
10078 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10079 return;
10080 }
10081
10082 4290659 const mapscr & l = *m;
10083
10084 4290659 BITMAP* b = bmp;
10085
10086
1/2
✓ Branch 0 taken 4290659 times.
✗ Branch 1 not taken.
4290659 if(rotation != 0)
10087 b = script_drawing_commands.AquireSubBitmap(256, 176);
10088
10089
10090 4290659 const int32_t maxX = isOffScreen ? 512 : 256;
10091
2/2
✓ Branch 0 taken 4280939 times.
✓ Branch 1 taken 9720 times.
4290659 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10092 4290659 bool transparent = opacity <= 128;
10093
10094
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4290659 times.
4290659 if(rotation != 0) // rotate
10095 {
10096 draw_mapscr(b, l, x1, y1, transparent);
10097
10098 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10099 script_drawing_commands.ReleaseSubBitmap(b);
10100 }
10101 else
10102 {
10103
2/2
✓ Branch 0 taken 755155984 times.
✓ Branch 1 taken 4290659 times.
759446643 for(int32_t i(0); i < 176; ++i)
10104 {
10105 755155984 const int32_t x2 = ((i&15)<<4) + x1;
10106 755155984 const int32_t y2 = (i&0xF0) + y1;
10107
10108
7/8
✓ Branch 0 taken 664698870 times.
✓ Branch 1 taken 90457114 times.
✓ Branch 2 taken 664698870 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 610281598 times.
✓ Branch 5 taken 54417272 times.
✓ Branch 6 taken 9155742 times.
✓ Branch 7 taken 601125856 times.
755155984 if(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY) //in clipping rect
10109 {
10110 601125856 const newcombo & c = combobuf[ l.data[i] ];
10111 601125856 const int32_t tile = combo_tile(c, x2, y2);
10112
10113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 601125856 times.
601125856 if(opacity < 128)
10114 {
10115 overcomboblocktranslucent(b, x2, y2, l.data[i], l.cset[i], 1, 1, 128);
10116
10117
10118 //overtiletranslucent16(b, tile, x2, y2, l.cset[i], c.flip, opacity);
10119 }
10120 else
10121 {
10122 601125856 overcomboblock(b, x2, y2, l.data[i], l.cset[i], 1, 1);
10123 //overtile16(b, tile, x2, y2, l.cset[i], c.flip);
10124 }
10125 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
10126 601125856 }
10127 755155984 }
10128 }
10129
10130 //putscr
10131 4327380 }
10132
10133
10134
10135 11134 void do_drawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10136 {
10137 //sdci[1]=layer
10138 //sdci[2]=map
10139 //sdci[3]=screen
10140 //sdci[4]=x
10141 //sdci[5]=y
10142 //sdci[6]=rotation
10143
10144 11134 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10145 11134 int32_t scrn = sdci[3]/10000;
10146 11134 int32_t x = sdci[4]/10000;
10147 11134 int32_t y = sdci[5]/10000;
10148 11134 int32_t x1 = x + xoffset;
10149 11134 int32_t y1 = y + yoffset;
10150 11134 int32_t rotation = sdci[6]/10000;
10151
10152 11134 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10153
10154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11134 times.
11134 if(index >= TheMaps.size())
10155 {
10156 al_trace("DrawScreen: invalid map or screen index. \n");
10157 return;
10158 }
10159
10160 11134 const mapscr & m = TheMaps[index];
10161
10162
10163 11134 BITMAP* b = bmp;
10164
10165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11134 times.
11134 if(rotation != 0)
10166 b = script_drawing_commands.AquireSubBitmap(256, 176);
10167
10168 //draw layer 0
10169 11134 draw_mapscr(b, m, x1, y1, false);
10170
10171
2/2
✓ Branch 0 taken 11134 times.
✓ Branch 1 taken 66804 times.
77938 for(int32_t i(0); i < 6; ++i)
10172 {
10173
2/2
✓ Branch 0 taken 14442 times.
✓ Branch 1 taken 52362 times.
66804 if(m.layermap[i] == 0) continue;
10174
10175 14442 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10176
10177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14442 times.
14442 if(layer_screen_index >= TheMaps.size())
10178 continue;
10179
10180 14442 bool trans = m.layeropacity[i] == 128;
10181
10182 //draw valid layers
10183 14442 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
10184 14442 }
10185
10186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11134 times.
11134 if(rotation != 0) // rotate
10187 {
10188 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10189 script_drawing_commands.ReleaseSubBitmap(b);
10190 }
10191 11134 }
10192
10193
10194 1173 void do_bmpdrawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10195 {
10196 //sdci[1]=layer
10197 //sdci[2]=map
10198 //sdci[3]=screen
10199 //sdci[4]=layer
10200 //sdci[5]=x
10201 //sdci[6]=y
10202 //sdci[7]=rotation
10203 //[8] noclip
10204 //sdci[9]=opacity
10205 //sdci[17] Bitmap Pointer
10206
10207 1173 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
10208
1/2
✓ Branch 0 taken 1173 times.
✗ Branch 1 not taken.
1173 if ( refbmp == NULL ) return;
10209
10210 1173 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10211 1173 int32_t scrn = sdci[3]/10000;
10212 1173 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10213 1173 int32_t x = sdci[5]/10000;
10214 1173 int32_t y = sdci[6]/10000;
10215 1173 int32_t rotation = sdci[7]/10000;
10216
10217 1173 byte noclip = 0;//(sdci[8]!=0);
10218 1173 int32_t opacity = sdci[8]/10000;
10219 //zprint2("Running bmp->DrawLayer(%d, %d, %d, %d, %d, %d, %d, %d)\n", sdci[1]/10000, map, scrn, sourceLayer, x, y, rotation, opacity);
10220 1173 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10221 1173 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10222
10223
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 6 times.
1173 if(!m) //no need to log it.
10224 6 return;
10225
10226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(index >= TheMaps.size())
10227 {
10228 Z_scripterrlog("DrawLayer: invalid map index \"%i\". Map count is %d.\n", index, TheMaps.size());
10229 return;
10230 }
10231
10232 1167 const mapscr & l = *m;
10233
10234 1167 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
10235
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if ( refbmp == NULL ) return;
10236
2/4
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1167 times.
✗ Branch 3 not taken.
1167 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
10237
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if(rotation != 0)
10238 b = script_drawing_commands.AquireSubBitmap(256, 176);
10239
10240
10241 1167 const int32_t maxX = isOffScreen ? 512 : 256;
10242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10243 1167 bool transparent = opacity <= 128;
10244
10245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(rotation != 0) // rotate
10246 {
10247 draw_mapscr(b, l, x, y, transparent);
10248
10249 rotate_sprite(refbmp, b, x, y, degrees_to_fixed(rotation));
10250 script_drawing_commands.ReleaseSubBitmap(b);
10251 }
10252 else
10253 {
10254
2/2
✓ Branch 0 taken 205392 times.
✓ Branch 1 taken 1167 times.
206559 for(int32_t i(0); i < 176; ++i)
10255 {
10256 205392 const int32_t x2 = ((i&15)<<4) + x;
10257 205392 const int32_t y2 = (i&0xF0) + y;
10258
10259 //if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10260 {
10261 205392 const newcombo & c = combobuf[ l.data[i] ];
10262 205392 const int32_t tile = combo_tile(c, x2, y2);
10263
10264
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205392 times.
205392 if(opacity < 128)
10265 overtiletranslucent16(refbmp, tile, x2, y2, l.cset[i], c.flip, opacity);
10266 else
10267 205392 overtile16(refbmp, tile, x2, y2, l.cset[i], c.flip);
10268
10269 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
10270 }
10271 205392 }
10272 }
10273
10274 //putscr
10275 1173 }
10276
10277
10278
10279 1092 void do_bmpdrawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10280 {
10281 //sdci[1]=layer
10282 //sdci[2]=map
10283 //sdci[3]=screen
10284 //sdci[4]=x
10285 //sdci[5]=y
10286 //sdci[6]=rotation
10287 //sdci[17] Bitmap Pointer
10288
10289 1092 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]-10);
10290
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if ( refbmp == NULL ) return;
10291
10292
2/4
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1092 times.
1092 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
10293
10294 1092 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10295 1092 int32_t scrn = sdci[3]/10000;
10296 1092 int32_t x = sdci[4]/10000;
10297 1092 int32_t y = sdci[5]/10000;
10298 1092 int32_t x1 = x + xoffset;
10299 1092 int32_t y1 = y + yoffset;
10300 1092 int32_t rotation = sdci[6]/10000;
10301
10302 1092 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10303
10304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if(index >= TheMaps.size())
10305 {
10306 al_trace("DrawScreen: invalid map or screen index. \n");
10307 return;
10308 }
10309
10310 1092 const mapscr & m = TheMaps[index];
10311
10312
10313 1092 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]-10);
10314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if ( refbmp == NULL ) return;
10315
10316
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0)
10317 b = script_drawing_commands.AquireSubBitmap(256, 176);
10318
10319 //draw layer 0
10320 1092 draw_mapscr(b, m, x1, y1, false);
10321
10322
2/2
✓ Branch 0 taken 1092 times.
✓ Branch 1 taken 6552 times.
7644 for(int32_t i(0); i < 6; ++i)
10323 {
10324
2/2
✓ Branch 0 taken 2118 times.
✓ Branch 1 taken 4434 times.
6552 if(m.layermap[i] == 0) continue;
10325
10326 2118 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10327
10328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2118 times.
2118 if(layer_screen_index >= TheMaps.size())
10329 continue;
10330
10331 2118 bool trans = m.layeropacity[i] == 128;
10332
10333 //draw valid layers
10334 2118 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
10335 2118 }
10336
10337
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0) // rotate
10338 {
10339 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10340 script_drawing_commands.ReleaseSubBitmap(b);
10341 }
10342 1092 }
10343
10344 void do_bmpdrawlayersolidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10345 {
10346 //sdci[1]=layer
10347 //sdci[2]=map
10348 //sdci[3]=screen
10349 //sdci[4]=layer
10350 //sdci[5]=x
10351 //sdci[6]=y
10352 //sdci[7]=rotation
10353 //sdci[8]=bool noclip
10354 //sdci[9] == opacity
10355
10356 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10357 int32_t scrn = sdci[3]/10000;
10358 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10359 int32_t x = sdci[5]/10000;
10360 int32_t y = sdci[6]/10000;
10361 int32_t x1 = x + xoffset;
10362 int32_t y1 = y + yoffset;
10363 int32_t rotation = sdci[7]/10000;
10364 byte noclip = (sdci[8]!=0);
10365 int32_t opacity = sdci[9]/10000;
10366
10367 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10368 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10369
10370 if(!m) //no need to log it.
10371 return;
10372
10373 if(index >= TheMaps.size())
10374 {
10375 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10376 return;
10377 }
10378
10379 const mapscr & l = *m;
10380
10381 BITMAP* b = bmp;
10382
10383 if(rotation != 0)
10384 b = script_drawing_commands.AquireSubBitmap(256, 176);
10385
10386
10387 const int32_t maxX = isOffScreen ? 512 : 256;
10388 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10389 bool transparent = opacity <= 128;
10390
10391 if(rotation != 0) // rotate
10392 {
10393 draw_map_solid(b, l, x1, y1);
10394
10395 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10396 script_drawing_commands.ReleaseSubBitmap(b);
10397 }
10398 else
10399 {
10400 BITMAP* square = create_bitmap_ex(8,16,16);
10401 BITMAP* subsquare = create_bitmap_ex(8,16,16);
10402 clear_to_color(subsquare,1);
10403 for(int32_t i(0); i < 176; ++i)
10404 {
10405 const int32_t x2 = ((i&15)<<4) + x1;
10406 const int32_t y2 = (i&0xF0) + y1;
10407
10408 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10409 {
10410 int32_t sol = (combobuf[l.data[i]].walk);
10411
10412 if ( sol & 1 )
10413 {
10414 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
10415 }
10416 if ( sol & 2 )
10417 {
10418 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
10419 }
10420 if ( sol & 4 )
10421 {
10422 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
10423 }
10424 if ( sol &8 ) {
10425 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
10426 }
10427
10428 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10429 }
10430 }
10431 destroy_bitmap(square);
10432 destroy_bitmap(subsquare);
10433 }
10434
10435 //putscr
10436 }
10437
10438 void do_bmpdrawlayersolidityr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10439 {
10440 //sdci[1]=layer
10441 //sdci[2]=map
10442 //sdci[3]=screen
10443 //sdci[4]=layer
10444 //sdci[5]=x
10445 //sdci[6]=y
10446 //sdci[7]=rotation
10447 //[8] noclip
10448 //sdci[9]=opacity
10449
10450
10451 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10452 int32_t scrn = sdci[3]/10000;
10453 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10454 int32_t x = sdci[5]/10000;
10455 int32_t y = sdci[6]/10000;
10456 int32_t x1 = x + xoffset;
10457 int32_t y1 = y + yoffset;
10458 int32_t rotation = sdci[7]/10000;
10459 byte noclip = (sdci[8]!=0);
10460 int32_t opacity = sdci[9]/10000;
10461
10462 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10463 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10464
10465 if(!m) //no need to log it.
10466 return;
10467
10468 if(index >= TheMaps.size())
10469 {
10470 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10471 return;
10472 }
10473
10474 const mapscr & l = *m;
10475
10476 BITMAP* b = bmp;
10477
10478 if(rotation != 0)
10479 b = script_drawing_commands.AquireSubBitmap(256, 176);
10480
10481
10482 const int32_t maxX = isOffScreen ? 512 : 256;
10483 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10484 bool transparent = opacity <= 128;
10485
10486 if(rotation != 0) // rotate
10487 {
10488 draw_map_solidity(b, l, x1, y1);
10489
10490 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10491 script_drawing_commands.ReleaseSubBitmap(b);
10492 }
10493 else
10494 {
10495 BITMAP* square = create_bitmap_ex(8,16,16);
10496 for(int32_t i(0); i < 176; ++i)
10497 {
10498 const int32_t x2 = ((i&15)<<4) + x1;
10499 const int32_t y2 = (i&0xF0) + y1;
10500
10501 if(noclip && (x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10502 {
10503 clear_to_color(square,(combobuf[l.data[i]].walk&15));
10504 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10505 }
10506 }
10507 destroy_bitmap(square);
10508 }
10509
10510 //putscr
10511 }
10512
10513 void do_bmpdrawlayercflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10514 {
10515 //sdci[1]=layer
10516 //sdci[2]=map
10517 //sdci[3]=screen
10518 //sdci[4]=layer
10519 //sdci[5]=x
10520 //sdci[6]=y
10521 //sdci[7]=rotation
10522 //[8] noclip
10523 //sdci[9]=opacity
10524
10525
10526 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10527 int32_t scrn = sdci[3]/10000;
10528 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10529 int32_t x = sdci[5]/10000;
10530 int32_t y = sdci[6]/10000;
10531 int32_t x1 = x + xoffset;
10532 int32_t y1 = y + yoffset;
10533 int32_t rotation = sdci[7]/10000;
10534
10535 byte noclip = (sdci[8]!=0);
10536 int32_t opacity = sdci[9]/10000;
10537
10538 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10539 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10540
10541 if(!m) //no need to log it.
10542 return;
10543
10544 if(index >= TheMaps.size())
10545 {
10546 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10547 return;
10548 }
10549
10550 const mapscr & l = *m;
10551
10552 BITMAP* b = bmp;
10553
10554 if(rotation != 0)
10555 b = script_drawing_commands.AquireSubBitmap(256, 176);
10556
10557
10558 const int32_t maxX = isOffScreen ? 512 : 256;
10559 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10560 bool transparent = opacity <= 128;
10561
10562 if(rotation != 0) // rotate
10563 {
10564 draw_map_cflag(b, l, x1, y1);
10565
10566 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10567 script_drawing_commands.ReleaseSubBitmap(b);
10568 }
10569 else
10570 {
10571 BITMAP* square = create_bitmap_ex(8,16,16);
10572 for(int32_t i(0); i < 176; ++i)
10573 {
10574 const int32_t x2 = ((i&15)<<4) + x1;
10575 const int32_t y2 = (i&0xF0) + y1;
10576
10577 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10578 {
10579 clear_to_color(square,l.sflag[i]);
10580 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10581 }
10582 }
10583 destroy_bitmap(square);
10584 }
10585
10586 //putscr
10587 }
10588
10589 void do_bmpdrawlayerctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10590 {
10591 //sdci[1]=layer
10592 //sdci[2]=map
10593 //sdci[3]=screen
10594 //sdci[4]=layer
10595 //sdci[5]=x
10596 //sdci[6]=y
10597 //sdci[7]=rotation
10598 //[8] noclip
10599 //sdci[9]=opacity
10600
10601 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10602 int32_t scrn = sdci[3]/10000;
10603 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10604 int32_t x = sdci[5]/10000;
10605 int32_t y = sdci[6]/10000;
10606 int32_t x1 = x + xoffset;
10607 int32_t y1 = y + yoffset;
10608 int32_t rotation = sdci[7]/10000;
10609
10610 byte noclip = (sdci[8]!=0);
10611 int32_t opacity = sdci[9]/10000;
10612 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10613 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10614
10615 if(!m) //no need to log it.
10616 return;
10617
10618 if(index >= TheMaps.size())
10619 {
10620 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10621 return;
10622 }
10623
10624 const mapscr & l = *m;
10625
10626 BITMAP* b = bmp;
10627
10628 if(rotation != 0)
10629 b = script_drawing_commands.AquireSubBitmap(256, 176);
10630
10631
10632 const int32_t maxX = isOffScreen ? 512 : 256;
10633 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10634 bool transparent = opacity <= 128;
10635
10636 if(rotation != 0) // rotate
10637 {
10638 draw_map_combotype(b, l, x1, y1);
10639
10640 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10641 script_drawing_commands.ReleaseSubBitmap(b);
10642 }
10643 else
10644 {
10645 BITMAP* square = create_bitmap_ex(8,16,16);
10646 for(int32_t i(0); i < 176; ++i)
10647 {
10648 const int32_t x2 = ((i&15)<<4) + x1;
10649 const int32_t y2 = (i&0xF0) + y1;
10650
10651 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10652 {
10653 clear_to_color(square,(combobuf[l.data[i]].type));
10654 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10655 }
10656 }
10657 destroy_bitmap(square);
10658 }
10659
10660 //putscr
10661 }
10662
10663 void do_bmpdrawlayerciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10664 {
10665 //sdci[1]=layer
10666 //sdci[2]=map
10667 //sdci[3]=screen
10668 //sdci[4]=layer
10669 //sdci[5]=x
10670 //sdci[6]=y
10671 //sdci[7]=rotation
10672 //[8] noclip
10673 //sdci[9]=opacity
10674
10675 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10676 int32_t scrn = sdci[3]/10000;
10677 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10678 int32_t x = sdci[5]/10000;
10679 int32_t y = sdci[6]/10000;
10680 int32_t x1 = x + xoffset;
10681 int32_t y1 = y + yoffset;
10682 int32_t rotation = sdci[7]/10000;
10683 byte noclip = (sdci[8]!=0);
10684 int32_t opacity = sdci[9]/10000;
10685
10686 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10687 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10688
10689 if(!m) //no need to log it.
10690 return;
10691
10692 if(index >= TheMaps.size())
10693 {
10694 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10695 return;
10696 }
10697
10698 const mapscr & l = *m;
10699
10700 BITMAP* b = bmp;
10701
10702 if(rotation != 0)
10703 b = script_drawing_commands.AquireSubBitmap(256, 176);
10704
10705
10706 const int32_t maxX = isOffScreen ? 512 : 256;
10707 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10708 bool transparent = opacity <= 128;
10709
10710 if(rotation != 0) // rotate
10711 {
10712 draw_map_comboiflag(b, l, x1, y1);
10713
10714 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10715 script_drawing_commands.ReleaseSubBitmap(b);
10716 }
10717 else
10718 {
10719 BITMAP* square = create_bitmap_ex(8,16,16);
10720 for(int32_t i(0); i < 176; ++i)
10721 {
10722 const int32_t x2 = ((i&15)<<4) + x1;
10723 const int32_t y2 = (i&0xF0) + y1;
10724
10725 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10726 {
10727 clear_to_color(square,(combobuf[l.data[i]].flag));
10728 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10729 }
10730 }
10731 destroy_bitmap(square);
10732 }
10733
10734 //putscr
10735 }
10736
10737
10738
10739 /////////////////////////////////////////////////////////
10740 // do primitives
10741 ////////////////////////////////////////////////////////
10742
10743 171158006 void do_primitives(BITMAP *targetBitmap, int32_t type, mapscr* theScreen, int32_t xoff, int32_t yoff)
10744 {
10745 171158006 color_map = &trans_table2;
10746
10747 //was this next variable ever used? -- DN
10748 //bool drawsubscr=false;
10749
10750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 171158006 times.
171158006 if(type > 7)
10751 return;
10752
3/4
✓ Branch 0 taken 55008919 times.
✓ Branch 1 taken 116149087 times.
✓ Branch 2 taken 55008919 times.
✗ Branch 3 not taken.
171158006 if(type >= 0 && theScreen->hidescriptlayers & (1<<type))
10753 return; //Script draws hidden for this layer
10754
2/2
✓ Branch 0 taken 1329522 times.
✓ Branch 1 taken 169828484 times.
171158006 if(!script_drawing_commands.is_dirty(type))
10755 169828484 return; //No draws to this layer
10756 //--script_drawing_commands[][] reference--
10757 //[][0]: type
10758 //[][1-16]: defined by type
10759 //[][17]: unused
10760 //[][18]: rendertarget
10761 //[][19]: unused
10762
10763 // Trying to match the old behavior exactly...
10764
2/2
✓ Branch 0 taken 545426 times.
✓ Branch 1 taken 784096 times.
1329522 const bool brokenOffset= ( (get_bit(extra_rules, er_BITMAPOFFSET)!=0) || (get_bit(quest_rules,qr_BITMAPOFFSETFIX)!=0) );
10765
10766 1329522 bool isTargetOffScreenBmp = false;
10767 1329522 const int32_t type_mul_10000 = type * 10000;
10768 1329522 const int32_t numDrawCommandsToProcess = script_drawing_commands.Count();
10769 1329522 FFCore.numscriptdraws = numDrawCommandsToProcess;
10770 1329522 int32_t xoffset=xoff, yoffset=yoff;
10771
2/2
✓ Branch 0 taken 56726517 times.
✓ Branch 1 taken 1329522 times.
58056039 for(int32_t i(0); i < numDrawCommandsToProcess; ++i)
10772 {
10773
2/2
✓ Branch 0 taken 13985405 times.
✓ Branch 1 taken 42741112 times.
56726517 if(!brokenOffset)
10774 {
10775 42741112 xoffset = 0;
10776 42741112 yoffset = 0;
10777 42741112 }
10778 56726517 int32_t *sdci = &script_drawing_commands[i][0];
10779
10780
2/2
✓ Branch 0 taken 29825020 times.
✓ Branch 1 taken 26901497 times.
56726517 if(sdci[1] != type_mul_10000)
10781 29825020 continue;
10782 // get the correct render target, if set.
10783 26901497 BITMAP *bmp = zscriptDrawingRenderTarget->GetTargetBitmap(sdci[18]);
10784
10785
2/2
✓ Branch 0 taken 6236208 times.
✓ Branch 1 taken 20665289 times.
26901497 if(!bmp)
10786 {
10787 // draw to screen with subscreen offset
10788
2/2
✓ Branch 0 taken 6900511 times.
✓ Branch 1 taken 13764778 times.
20665289 if(!brokenOffset)
10789 {
10790 13764778 xoffset = xoff;
10791 13764778 yoffset = yoff;
10792 13764778 }
10793 20665289 bmp = targetBitmap;
10794 20665289 }
10795 else
10796 {
10797 //not drawing to screen, so no subscreen offset
10798
2/2
✓ Branch 0 taken 6152841 times.
✓ Branch 1 taken 83367 times.
6236208 if(brokenOffset)
10799 {
10800 83367 xoffset = 0;
10801 83367 yoffset = 0;
10802 83367 }
10803 6236208 isTargetOffScreenBmp = true;
10804 }
10805
10806
37/82
✗ Branch 0 not taken.
✓ Branch 1 taken 1785700 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 759760 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1850 times.
✓ Branch 6 taken 933117 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 261359 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 787250 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1198548 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 3095380 times.
✓ Branch 18 taken 9915097 times.
✓ Branch 19 taken 936091 times.
✓ Branch 20 taken 47706 times.
✓ Branch 21 taken 1187639 times.
✓ Branch 22 taken 153213 times.
✓ Branch 23 taken 9266 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 814852 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 4327380 times.
✓ Branch 31 taken 11134 times.
✓ Branch 32 taken 7818 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 1480 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 502 times.
✓ Branch 37 taken 144 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 80910 times.
✓ Branch 40 taken 59428 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 824 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 167316 times.
✓ Branch 45 taken 784 times.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 45504 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✓ Branch 56 taken 1173 times.
✓ Branch 57 taken 1092 times.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✓ Branch 60 taken 1024 times.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✓ Branch 63 taken 236166 times.
✗ Branch 64 not taken.
✓ Branch 65 taken 909 times.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✓ Branch 68 taken 26369 times.
✓ Branch 69 taken 2790 times.
✓ Branch 70 taken 34653 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✓ Branch 78 taken 6363 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 906 times.
✗ Branch 81 not taken.
26901497 switch(sdci[0])
10807 {
10808 case RECTR:
10809 {
10810 1785700 do_rectr(bmp, sdci, xoffset, yoffset);
10811 }
10812 1785700 break;
10813 case FRAMER:
10814 {
10815 do_framer(bmp, sdci, xoffset, yoffset);
10816 }
10817 break;
10818
10819
10820 case CIRCLER:
10821 {
10822 759760 do_circler(bmp, sdci, xoffset, yoffset);
10823 }
10824 759760 break;
10825
10826 case ARCR:
10827 {
10828 do_arcr(bmp, sdci, xoffset, yoffset);
10829 }
10830 break;
10831
10832 case ELLIPSER:
10833 {
10834 1850 do_ellipser(bmp, sdci, xoffset, yoffset);
10835 }
10836 1850 break;
10837
10838 case LINER:
10839 {
10840 933117 do_liner(bmp, sdci, xoffset, yoffset);
10841 }
10842 933117 break;
10843
10844 case SPLINER:
10845 {
10846 do_spliner(bmp, sdci, xoffset, yoffset);
10847 }
10848 break;
10849
10850 case PUTPIXELR:
10851 {
10852 261359 do_putpixelr(bmp, sdci, xoffset, yoffset);
10853 }
10854 261359 break;
10855 case PIXELARRAYR:
10856 {
10857 //Z_scripterrlog("Reached case PIXELARRAYR\n");
10858 do_putpixelsr(bmp, i, sdci, xoffset, yoffset);
10859 }
10860 break;
10861
10862 case TILEARRAYR:
10863 {
10864 //Z_scripterrlog("Reached case PIXELARRAYR\n");
10865 do_fasttilesr(bmp, i, sdci, xoffset, yoffset);
10866 }
10867 break;
10868
10869 case LINESARRAY:
10870 {
10871 //Z_scripterrlog("Reached case PIXELARRAYR\n");
10872 do_linesr(bmp, i, sdci, xoffset, yoffset);
10873 }
10874 break;
10875
10876 case COMBOARRAYR:
10877 {
10878 //Z_scripterrlog("Reached case PIXELARRAYR\n");
10879 do_fastcombosr(bmp, i, sdci, xoffset, yoffset);
10880 }
10881 break;
10882
10883
10884
10885 case DRAWTILER:
10886 {
10887 787250 do_drawtiler(bmp, sdci, xoffset, yoffset);
10888 }
10889 787250 break;
10890
10891 case DRAWTILECLOAKEDR:
10892 {
10893 do_drawtilecloakedr(bmp, sdci, xoffset, yoffset);
10894 }
10895 break;
10896
10897 case DRAWCOMBOR:
10898 {
10899 1198548 do_drawcombor(bmp, sdci, xoffset, yoffset);
10900 }
10901 1198548 break;
10902
10903 case DRAWCOMBOCLOAKEDR:
10904 {
10905 do_drawcombocloakedr(bmp, sdci, xoffset, yoffset);
10906 }
10907 break;
10908
10909 case FASTTILER:
10910 {
10911 3095380 do_fasttiler(bmp, sdci, xoffset, yoffset);
10912 }
10913 3095380 break;
10914
10915 case FASTCOMBOR:
10916 {
10917 9915097 do_fastcombor(bmp, sdci, xoffset, yoffset);
10918 }
10919 9915097 break;
10920
10921 case DRAWCHARR:
10922 {
10923 936091 do_drawcharr(bmp, sdci, xoffset, yoffset);
10924 }
10925 936091 break;
10926
10927 case DRAWINTR:
10928 {
10929 47706 do_drawintr(bmp, sdci, xoffset, yoffset);
10930 }
10931 47706 break;
10932
10933 case DRAWSTRINGR:
10934 {
10935 1187639 do_drawstringr(bmp, i, sdci, xoffset, yoffset);
10936 }
10937 1187639 break;
10938
10939 case DRAWSTRINGR2:
10940 {
10941 153213 do_drawstringr2(bmp, i, sdci, xoffset, yoffset);
10942 }
10943 153213 break;
10944
10945 case QUADR:
10946 {
10947 9266 do_drawquadr(bmp, sdci, xoffset, yoffset);
10948 }
10949 9266 break;
10950
10951 case QUAD3DR:
10952 {
10953 do_drawquad3dr(bmp, i, sdci, xoffset, yoffset);
10954 }
10955 break;
10956
10957 case TRIANGLER:
10958 {
10959 do_drawtriangler(bmp, sdci, xoffset, yoffset);
10960 }
10961 break;
10962
10963 case TRIANGLE3DR:
10964 {
10965 do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset);
10966 }
10967 break;
10968
10969 case POLYGONR:
10970 {
10971 do_polygonr(bmp, i, sdci, xoffset, yoffset);
10972 }
10973 break;
10974
10975
10976 case BITMAPR:
10977 {
10978 814852 do_drawbitmapr(bmp, sdci, xoffset, yoffset);
10979 }
10980 814852 break;
10981
10982 case BITMAPEXR:
10983 {
10984 do_drawbitmapexr(bmp, sdci, xoffset, yoffset);
10985 }
10986 break;
10987
10988 case DRAWLAYERR:
10989 {
10990 4327380 do_drawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
10991 }
10992 4327380 break;
10993
10994 case DRAWSCREENR:
10995 {
10996 11134 do_drawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
10997 }
10998 11134 break;
10999
11000 7818 case BMPRECTR: bmp_do_rectr(bmp, sdci, xoffset, yoffset); break;
11001 case BMPFRAMER: bmp_do_framer(bmp, sdci, xoffset, yoffset); break;
11002 1480 case BMPCIRCLER: bmp_do_circler(bmp, sdci, xoffset, yoffset); break;
11003 case BMPARCR: bmp_do_arcr(bmp, sdci, xoffset, yoffset); break;
11004 502 case BMPELLIPSER: bmp_do_ellipser(bmp, sdci, xoffset, yoffset); break;
11005 144 case BMPLINER: bmp_do_liner(bmp, sdci, xoffset, yoffset); break;
11006 case BMPSPLINER: bmp_do_spliner(bmp, sdci, xoffset, yoffset); break;
11007 80910 case BMPPUTPIXELR: bmp_do_putpixelr(bmp, sdci, xoffset, yoffset); break;
11008 59428 case BMPDRAWTILER: bmp_do_drawtiler(bmp, sdci, xoffset, yoffset); break;
11009 case BMPDRAWTILECLOAKEDR: bmp_do_drawtilecloakedr(bmp, sdci, xoffset, yoffset); break;
11010 824 case BMPDRAWCOMBOR: bmp_do_drawcombor(bmp, sdci, xoffset, yoffset); break;
11011 case BMPDRAWCOMBOCLOAKEDR: bmp_do_drawcombocloakedr(bmp, sdci, xoffset, yoffset); break;
11012 167316 case BMPFASTTILER: bmp_do_fasttiler(bmp, sdci, xoffset, yoffset); break;
11013 784 case BMPFASTCOMBOR: bmp_do_fastcombor(bmp, sdci, xoffset, yoffset); break;
11014 case BMPDRAWCHARR: bmp_do_drawcharr(bmp, sdci, xoffset, yoffset); break;
11015 case BMPDRAWINTR: bmp_do_drawintr(bmp, sdci, xoffset, yoffset); break;
11016 case BMPDRAWSTRINGR: bmp_do_drawstringr(bmp, i, sdci, xoffset, yoffset); break;
11017 45504 case BMPDRAWSTRINGR2: bmp_do_drawstringr2(bmp, i, sdci, xoffset, yoffset); break;
11018 case BMPQUADR: bmp_do_drawquadr(bmp, sdci, xoffset, yoffset); break;
11019 case BMPQUAD3DR: bmp_do_drawquad3dr(bmp, i, sdci, xoffset, yoffset); break;
11020
11021 case BITMAPGETPIXEL: bmp_do_getpixelr(bmp, sdci, xoffset, yoffset); break;
11022 case BMPTRIANGLER: bmp_do_drawtriangler(bmp, sdci, xoffset, yoffset); break;
11023 case BMPTRIANGLE3DR: bmp_do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset); break;
11024 case BMPPOLYGONR: bmp_do_polygonr(bmp, i, sdci, xoffset, yoffset); break;
11025 1173 case BMPDRAWLAYERR: do_bmpdrawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11026 1092 case BMPDRAWSCREENR: do_bmpdrawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11027 case BMPDRAWSCREENSOLIDR: do_bmpdrawscreen_solidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11028 case BMPDRAWSCREENSOLID2R: do_bmpdrawscreen_solidr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11029 1024 case BMPDRAWSCREENCOMBOFR: do_bmpdrawscreen_cflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11030 case BMPDRAWSCREENCOMBOIR: do_bmpdrawscreen_ciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11031 case BMPDRAWSCREENCOMBOTR: do_bmpdrawscreen_ctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11032 236166 case BMPBLIT: bmp_do_drawbitmapexr(bmp, sdci, xoffset, yoffset); break;
11033 case BMPMODE7: bmp_do_mode7r(bmp, sdci, xoffset, yoffset); break;
11034 909 case BMPBLITTO: bmp_do_blittor(bmp, sdci, xoffset, yoffset); break;
11035 case READBITMAP: bmp_do_readr(bmp, i, sdci, xoffset, yoffset); break;
11036 case WRITEBITMAP: bmp_do_writer(bmp, i, sdci, xoffset, yoffset); break;
11037 26369 case CLEARBITMAP: bmp_do_clearr(bmp, sdci, xoffset, yoffset); break;
11038 2790 case BITMAPCLEARTOCOLOR: bmp_do_clearcolorr(bmp, sdci, xoffset, yoffset); break;
11039 34653 case REGENERATEBITMAP: bmp_do_regenr(bmp, sdci, xoffset, yoffset); break;
11040
11041 case BMPDRAWLAYERSOLIDR: do_bmpdrawlayersolidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11042 case BMPDRAWLAYERCFLAGR: do_bmpdrawlayercflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11043 case BMPDRAWLAYERCTYPER: do_bmpdrawlayerctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11044 case BMPDRAWLAYERCIFLAGR: do_bmpdrawlayerciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11045 case BMPDRAWLAYERSOLIDITYR: do_bmpdrawlayersolidityr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
11046 case BMPWRITETILE: do_bmpwritetile(bmp, sdci, xoffset, yoffset); break;
11047 case BMPDITHER: do_bmpdither(bmp, sdci, xoffset, yoffset); break;
11048 6363 case BMPREPLCOLOR: do_bmpreplcol(bmp, sdci, xoffset, yoffset); break;
11049 case BMPSHIFTCOLOR: do_bmpshiftcol(bmp, sdci, xoffset, yoffset); break;
11050 906 case BMPMASKDRAW: do_bmpmaskdraw(bmp, sdci, xoffset, yoffset); break;
11051 case BMPMASKBLIT: do_bmpmaskblit(bmp, sdci, xoffset, yoffset); break;
11052 }
11053 26901497 }
11054
11055
11056 1329522 color_map=&trans_table;
11057 171158006 }
11058
11059 7172713 void CScriptDrawingCommands::Clear()
11060 {
11061 7172713 scb.update();
11062 7172713 dirty_layers.clear();
11063
2/2
✓ Branch 0 taken 4958239 times.
✓ Branch 1 taken 2214474 times.
7172713 if(commands.empty())
11064 4958239 return;
11065
11066 //only clear what was used.
11067 2214474 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
11068 2214474 count = 0;
11069
11070 2214474 draw_container.Clear();
11071 7172713 }
11072 CScriptDrawingCommands* CScriptDrawingCommands::pop_commands()
11073 {
11074 CScriptDrawingCommands* ret = new CScriptDrawingCommands();
11075 if(commands.empty())
11076 return ret;
11077 ret->push_commands(this, false);
11078
11079 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
11080 count = 0;
11081
11082 draw_container.Clear();
11083 return ret;
11084 }
11085 void CScriptDrawingCommands::push_commands(CScriptDrawingCommands* other, bool del)
11086 {
11087 commands.insert(commands.end(), other->commands.begin(), other->commands.end());
11088 count += other->count;
11089 if(del) delete other;
11090 }
11091
11092 9182 void do_script_draws(BITMAP *targetBitmap, mapscr* theScreen, int32_t xoff, int32_t yoff, bool hideLayer7)
11093 {
11094
2/2
✓ Branch 0 taken 9181 times.
✓ Branch 1 taken 1 times.
9182 if(XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
11095
2/2
✓ Branch 0 taken 8927 times.
✓ Branch 1 taken 255 times.
9182 if(XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
11096 9182 do_primitives(targetBitmap, 0, theScreen, xoff, yoff);
11097 9182 do_primitives(targetBitmap, 1, theScreen, xoff, yoff);
11098
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9181 times.
9182 if(!XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
11099
2/2
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 8927 times.
9182 if(!XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
11100 9182 do_primitives(targetBitmap, 4, theScreen, xoff, yoff);
11101 9182 do_primitives(targetBitmap, 5, theScreen, xoff, yoff);
11102 9182 do_primitives(targetBitmap, 6, theScreen, xoff, yoff);
11103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9182 times.
9182 if(!hideLayer7) do_primitives(targetBitmap, 7, theScreen, xoff, yoff);
11104 9182 }
11105